We are seriously considering this feature for C# and VB, and will be prototyping it in coming months. Syntax in C# would be
e?.x // member access
e?.M(…) // method invocation
e?[…] // indexing
Semantically this will be similar to
(e == null) ? null : e.x
etc., except that e will only be evaluated once of course.
If the type of e.x (etc) is a non-nullable value type S, then the type of e?.x is S?. Otherwise the type of e?.x is the same as that of e.×. If we can’t tell whether the type is a non-nullable value type (because it is a type parameter without sufficient constraints) we’ll probably give a compile-time error.
Thanks for all the great comments!
C# Language PM
1,630 votesDiego B. Fernandez gave this 3 votes ·
Committed! http://aka.ms/gitinitvsDiego B. Fernandez commented
Hope it will fill my need for versioning + ALM