public class ListTest
{
public List<int> MyList;
public ListTest()
{
MyList = new List<int> { 1, 2, 3 };
}
}
var listTest = new ListTest()
{
MyList = {4,5,6}
};
listTest.MyList
の値は分かりますか?C#new操作バグ?
それは{1,2,3,4,5,6}
誰かがそれを説明することができますでしょう?
しかし、それは動作します。それは.addと同じですか? –
@ L.Tim、それは代入演算子ですが、そうではありません。これは、 '{}'の間の項目に対するループの文法的な砂糖であり、すでにその項目を_初期化済みのコレクションに追加しています。 –