NullStringToEmptyString

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

Description

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.

Details

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

Double click on the code to select all.

 

;