public static string NullStringToEmptyString(this string input)
	if (input == null)
		return string.Empty;

	return input;
string myString = null;
myString = myString.NullStringToEmptyString();
myString = myString.ToLower();// some operation with no need for null check


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.


  • Author: Joseph K
  • Submitted on: 11/3/2014 11:18:13 AM
  • Language: C#
  • Type: string
  • Views: 2029

Double click on the code to select all.