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?"

Code answers related to "Javascript"

Browse Popular Code Answers by Language