Friday, 26 February 2016

?. operator not supported in lambdas

I love working with the new C# 6 as there have been a few changes that are really great. For example, the null check operator ?. operator is great, as it shortens code. Unfortunately, I discovered today that it is not implemented in lambdas. Thus, I can't write...

q = q.Where(place => place.PlaceStatus?.Key == this.Status.Key);

but have to write the old style check...

q = q.Where(place => place.PlaceStatus != null
            && place.PlaceStatus.Key == this.Status.Key);

Hopefully, Microsoft will fix this in a future release.

No comments:

Post a Comment