I want to build my own class in C# that is initialized by multiple parameters with curly bracers, like string[]
string[] x = new string[] {
"string1",
"string2",
"string3"
}
Is it possible?
Edit I am sorry for not making myself clear. I wanted a class that can be initialized in an elegant way, with variable amount of parameters.
To support collection initializer syntax, your class needs to implement IEnumerable and have a public Add method.
Example:
Usage:
Alternatively, you can define a constructor that takes a variable number of arguments. You can do this using the params keyword.
Example:
Usage: