Tag Archives: csharp

stringObject.IsNullOrWhiteSpace() a simple c# extension method

Every time doing String.IsNullOrWhiteSpace(input) is irritating. Moreover we try to input. and look for this method in intelligence. But it won’t be there, as it is static, unless we do String. we don’t see this method.

Writing an extension method will save us this trouble.

public static class MustHaveCSharpExtensions
{
	public static bool IsNullOrWhiteSpace(this string input)
	{
		return String.IsNullOrWhiteSpace(input);
	}
}

c# new feature request : AutoInitListsOnFirstUse

Another sugar coating – a compiler should easily generate code for this (?) without any side effects. why force people to do new boiler plate code ?

List<string> myListOfStrings;

myListOfStrings.Add(“firstString”);

This throws NullReferenceException until we do new List<string>();

The probability of it happening is more when this is part of another data class, which we initialized but forgot to look into all hose other initializations we need to do.

In case somebody want to avoid this behavior we should have an attribute to support old behavior.

[SansAutoInitListOnFirstUse]