I'm looking for a 'safe' dot notation in VB.net. Does such a thing exist - in VB.NET or any language? What I want to be able to do is, when using non-nullable legacy objects, to solve a problem like:
"if there as a plan, if there is a case, if it has a person, that person's spouse, else, nothing (VBSpeak for Null)."
and avoid doing this:
Dim Spouse as Person = Nothing
if Case.Plan isnot nothing then
if Case.Plan.Person isnot Nothing
Spouse = Case.Plan.Person.Spouse
Dim Spouse as Person = Case~Plan~Person~Spouse
dim MyVar as string = XMLDoc.DocumentElement.SelectSingleNode("Name").InnerText
VB.NET 14 introduced the null-conditional operator to address this. This operator is also short-circuiting.
Dim Spouse as Person = Case?.Plan?.Person?.Spouse
Used to test for null before performing a member access (?.) or index (?[) operation. These operators help you write less code to handle null checks, especially for descending into data structures.