このコードは正常にコンパイルされますが、コンパイルに失敗するはずです。また、実行するとNullReferenceException
. Bar
欠落しているコードは、プロパティの初期化における「新しいバー」です。
class Bar
{
public string Name { get; set; }
}
class Foo
{
public Bar Bar { get; set; }
}
class Program
{
static void Main(string[] args)
{
var foo = new Foo
{
Bar = { Name = "Hello" }
};
}
}
これは既知のバグですか?