Possible Duplicate:
C# if-null-then-null expression
What I miss in C# is the treatment of null references like in sql server:
var a = SomeObject.Property1.Property2.Property3.Property4
If any of properties is null then I get NullReferenceException. Sometimes it would be more convenient if a
would be set to null with no error and I could simply check for this.
Similarly,
var a = SomeList.FirstOrDefault(...).Select(...)
this would also throw exception if sequence would contain no elements rather then setting a
to null.
So my question: is there short and nice way (using extensions maybe?) to implement sql-like behaviour in these scenarios?