In the following code, why is pdList[0] null while _propertyDetails is a properly instantiated object? I was under the impression that I’m adding a reference to pdList that points to the same object as _propertyDetails, so after instantiating this object, both references should be non-null?
PropertyDetailsModel _propertyDetails = null;
var pdList = new List<PropertyDetailsModel> { _propertyDetails };
_propertyDetails = PropertyDetailsModel.Read(PropertyId);
Forgive me if I’m missing something basic; I’ve been battling to narrow my problem down to this issue for several hours, and my brain is tired.
It’s (apparently) a reference type, so when you create
pdList, the reference gets copied, but it isnullat that point. Assigning to_propertyDetailslater does not change thenullreference that’s already inpdList.