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


Essentially the implementation of the sql 'isnull' function, allowing the string type (when null) to be replaced with another value.


/// <summary>
	/// If the string is null, converts it to the default string specified. Essentially the same as the SQL IsNull()
	/// function.
	/// </summary>
	/// <param name="inString"></param>
	/// <param name="defaultString"></param>
	/// <returns></returns>
	public static string IsNull(this string inString, string defaultString)
		if (inString==null)
			return defaultString;
		else return inString;


string myString = null;
string aSaferString = myString.IsNull(string.Empty);

Author: Steve Mentzer

Submitted on: 20 okt 2009

Language: C#

Type: System.String

Views: 5289