Simple整数を含むクラスがありますnumber。このコードの使用:
Simple b = new Simple();
List<Simple> list = new List<Simple>();
list.Add(b);
b.number = 6;
b = null;
Debug.WriteLine("The value of b is " + b);
Debug.WriteLine("And the value of the clown in the list is " + list[0].number);
デバッグはとを返しThe value of b isますAnd the value of the clown in the list is 6。
bにを追加するとlist、への参照bが保存されると想定できます。次に、をnullbにlistすることにより、オブジェクトへの参照が含まれているためb、の値を出力できますnumber。
ただし、のメンバーを変更bして、リストに格納されている参照に反映させることができる場合、なぜ?b = nullの値に反映されないのlist[0]ですか?私はこれが価値と参照と関係があると推測することができるだけです。
誰かを助けますか?