I have a DateTime? variable, sometimes the value is null, how can I return an empty string \"\" when the value is null or
DateTime?
null
\"\"
You could write an extension method
public static string ToStringSafe(this DateTime? t) { return t.HasValue ? t.Value.ToString() : String.Empty; } ... var str = myVariable.ToStringSafe();