how to do tostring for a possibly null object 3f

Solutions on MaxInterview for how to do tostring for a possibly null object 3f by the best coders in the world

showing results for - "how to do tostring for a possibly null object 3f"
Marco
07 Jan 2020
1string s = (myObjc ?? "").ToString()
2
Mathilda
12 Jan 2020
1string s = myObj?.ToString() ?? "";
2
Alberto
24 Feb 2016
1string s = (myObjc ?? (Object)"").ToString()
2string s = ((Object)myObjc ?? "").ToString()
3
Karl
03 May 2016
1string s = (myObj ?? String.Empty).ToString();
2
Yasser
05 Jan 2018
1public static string ToStringNullSafe(this object value)
2{
3    return (value ?? string.Empty).ToString();
4}
5
Paola
16 Aug 2018
1string s = $"{myObj}";
2