The following code compiles, but fails with a NullReferenceException
:
class Test
{
public Dictionary<string, string> Dictionary { get; set; }
}
static void Main(string[] args)
{
var x = new Test
{
Dictionary = // fails
{
{ "key", "value" }, { "key2", "value2" }
}
};
}
If you replace the line marked 'fails' with the following, it works (as expected):
Dictionary = new Dictionary<string, string>
Is there any purpose to the failing syntax--can it be used successfully in some other case? Or is this an oversight in the compiler?