これはバグですか、それとも「??」演算子の解釈が間違っていますか? 以下の get プロパティとコメントを確認してください。
C# .NET 3.5 を使用しています
private List<MyType> _myTypeList;
private List<MyType> MyTypeList
{
get
{
//The two code lines below should each behave as the three under, but they don't?
//The ones uncommented are working, the commented result in my list always returning empty (newly created I suppose).
//return _myTypeList ?? new List<MyType>();
//return _myTypeList == null ? new List<MyType>() : _myTypeList;
if (_myTypeList == null)
_myTypeList = new List<MyType>();
return _myTypeList;
}
}
編集:新しく尋ねられたときに質問を見たすべての人に申し訳ありませんが、そこにいくつかのエラーがあり、みんなを混乱させました。
素早いフィードバックをありがとうございます。私は今、私が犯したエラーを理解しました。ありがとう!