I often use null propagating operator in my code because it gives me more readable code, specially in long queries I don't have to null-check every single class that is used.
The following code throws a compile error that we can't use null propagating operator in lambda.
var cnt = humans.AsQueryable().Count(a => a.House?[0].Price == 5000);
The error :
Error CS8072 An expression tree lambda may not contain a null propagating operator.
C# Could easily translate above code to the code to following code if really can't do anything else!
var cnt = humans.AsQueryable().Count(a => a.House != null && a.House[0].Price == 5000);
I'm curious why C# does nothing and simply throws a compiler error?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…