I just noticed that property assignment is not allowed in combination with the null conditional operator. With methods is it not a problem at all though.
I always thought that properties are just syntactic sugar for setter methods.
item?.SetMarker(Marker.Start); // Perfectly fine
item?.Marker = Marker.Start; // Error CS0131 The left-hand side of an assignment must be a variable, property or indexer
So why is one allowed and the other not?
I'm pretty sure there is a good theoretical reason. With the small hope of getting smarter I just try to know why :)
PS - I noticed the same behaviour in TypeScript.
In the second line, when
itemis null, it does not have anyMarker, so you are not able to assign any value to it.On the other hand, In the first line, when
itemis null,SetMarkermethod is not even called and in another word you do not try to assign anything.