IsNullThenEmpty

	/// <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;
		else
			return inString;
	}			
Example:
string theUserData = someTextBox.Text.IsNullThenEmpty();

Description

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

Details

Double click on the code to select all.

 

;