NullStringToEmptyString
If input is null, returns empty string. Otherwise returns original input. After using this method, you can use all string methods without the danger of null exception.
Source
public static string NullStringToEmptyString(this string input)
{
if (input == null)
{
return string.Empty;
}
return input;
}
Example
string myString = null;
myString = myString.NullStringToEmptyString();
myString = myString.ToLower();// some operation with no need for null check