Is there a difference between these two lines?
MyName = (s.MyName == null) ? string.Empty : s.MyName
or
MyName = s.MyName ?? string.Empty
Is there a difference between these two lines?
MyName = (s.MyName == null) ? string.Empty : s.MyName
or
MyName = s.MyName ?? string.Empty
The only difference is whether you evaluate
s.MyName
twice or once. The first will do it twice in the case thats.MyName
is not null, the second will only ever evaluate it once.In most cases, this difference doesn't matter, and I'd go with the second because it's more clear and concise.