I just noticed that the following is possible in C# written in Visual Studio 2015, but I've never seen it before:
public class X
{
public int A { get; set; }
public Y B { get; set; }
}
public class Y
{
public int C {get; set; }
}
public void Foo()
{
var x = new X { A = 1, B = { C = 3 } };
}
My expectation was for Foo to have to be implemented like this:
public void Foo()
{
var x = new X { A = 1, B = new Y { C = 3 } };
}
Note that there is no need to call new Y
.
Is this new in C# 6? I haven't seen any mention of this in the release notes, so maybe it's always been there?