Answers for "How to do ToString for a possibly null object?"

0

How to do ToString for a possibly null object?

string s = (myObjc ?? "").ToString()
Posted by: Guest on November-20-2020
0

How to do ToString for a possibly null object?

string s = (myObjc ?? (Object)"").ToString()
string s = ((Object)myObjc ?? "").ToString()
Posted by: Guest on November-20-2020
0

How to do ToString for a possibly null object?

string s = myObj?.ToString() ?? "";
Posted by: Guest on November-20-2020
0

How to do ToString for a possibly null object?

string s = $"{myObj}";
Posted by: Guest on November-20-2020
0

How to do ToString for a possibly null object?

string s = (myObj ?? String.Empty).ToString();
Posted by: Guest on November-20-2020
0

How to do ToString for a possibly null object?

public static string ToStringNullSafe(this object value)
{
    return (value ?? string.Empty).ToString();
}
Posted by: Guest on November-20-2020

Code answers related to "How to do ToString for a possibly null object?"

Browse Popular Code Answers by Language