C Sharp - Null Topics

Null Coalescing Operator

Uses the ?? operator

For example

1
X ?? y 

Means – if x is non-null, evaluate to x, otherwise Y

Null conditional operators

Aka Null conditional operators – aka short-circuiting
If A is null, then A?.x or a?[x] will be null
If A is not null, than a?.x and a?[x] will be the same as a.x and a[x]

1
2
message.To.Add(new MailboxAddress(toName ?? _emailConfig.UserName
, toEmailAddr ?? _emailConfig.UserName));

In this case, if toName is null, then use _mailConfig.UserName, if toEmailAddr is null then use _emailConfig.UserName