Is there a difference between these two lines?
MyName = (s.MyName == null) ? string.Empty : s.MyName
or
MyName = s.MyName ?? st
If the property is more than a simple getter, you might be executing a function twice in the non-null case for the first one.
If the property is in a stateful object, then the second call to the property might return a different result:
class MyClass
{
private IEnumerator _next = Next();
public MyClass()
{
this._next.MoveNext();
}
public string MyName
{
get
{
var n = this._next.Current;
this._next.MoveNext();
return n;
}
}
public static IEnumerator Next()
{
yield return "foo";
yield return "bar";
}
}
Also, in the non-string case, the class might overload == to do something different than the ternary operator. I don't believe that the ternary operator can be overloaded.