Pac0
0
Q:

How to do ToString for a possibly null object?

string s = (myObjc ?? "").ToString()
0
string s = (myObj ?? String.Empty).ToString();
0
string s = $"{myObj}";
0
string s = myObj?.ToString() ?? "";
0
public static string ToStringNullSafe(this object value)
{
    return (value ?? string.Empty).ToString();
}
0
string s = (myObjc ?? (Object)"").ToString()
string s = ((Object)myObjc ?? "").ToString()
0

New to Communities?

Join the community