C# inline question mark on object

84

C# inline question mark on object -

public class A {
  string PropertyOfA { get; set; }
}

A myA = null;
var foo = "bar";
string bar = (a == null ? null : a.PropertyOfA);
// both the same
if (a?.PropertyOfA != foo || bar != foo)
{
    // do something
}

Comments

Submit
0 Comments