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


A handy extension method for System.String that eliminates this pattern when trying to avoid null reference exceptions. if (someString==null) someString=string.Empty;


/// <summary>
	/// if the string is NULL, converts it to string.empty. Helpful when trying to avoid null conditions.
	/// </summary>
	/// <param name="inString"></param>
	/// <returns></returns>
	public static string IsNullThenEmpty(this string inString)
		if (inString==null)
			return string.Empty;
			return inString;


string theUserData = someTextBox.Text.IsNullThenEmpty();

Author: Steve Mentzer

Submitted on: 20 okt. 2009

Language: C#

Type: System.String

Views: 4833