ExtensionMethod.NET Home of 876 C#, Visual Basic, F# and Javascript extension methods


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.


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

Author: Joseph K

Submitted on: 3 nov. 2014

Language: C#

Type: string

Views: 4499