public static void Main()
string nullString = null;
Console.WriteLine("nullString is null? {0}",nullString == null);
string emptyString = nullString.EmptyIfNull();
Console.WriteLine("emptyString is null? {0}",emptyString == null);
string anotherNullString = emptyString.NullIfEmpty();
Console.WriteLine("anotherNullString is null? {0}",anotherNullString == null);
static class StringExtensions
public static string EmptyIfNull(this string text)
return text ?? String.Empty;
public static string NullIfEmpty(this string text)
return string.Empty == text ? null : text;