I came across a property of the type String array during my work and decided to be smart about it and add an anonymous array of values to it, since I didn't need an array of values I was only going to use once sticking around. To my surprise though, it's not possible?
class Foo
{
public String[] bar { get; set; }
}
static void Main(string[] args)
{
Foo foo = new Foo();
String[] arr = { "val1", "val2", "val3" };
foo.bar = arr;
foreach (String bar in foo.bar)
{
Console.WriteLine(bar);
}
}
Not surprisingly outputs: "val1" "val2" "val3"
But!
static void Main(string[] args)
{
Foo foo = new Foo();
foo.bar = {"val1", "val2", "val3"};
}
Throws all kinds of nasty compiler errors.
Googled turned up short of an answer, so I'm turning to SO. Why is this not possible?