String.IsNullOrWhiteSpace has been introduced in .NET 4. If you are not targeting .NET 4 you could easily write your own:
public static class StringExtensions { public static bool IsNullOrWhiteSpace(string value) { if (value != null) { for (int i = 0; i < value.Length; i++) { if (!char.IsWhiteSpace(value[i])) { return false; } } } return true; } }
which could be used like this:
bool isNullOrWhiteSpace = StringExtensions.IsNullOrWhiteSpace("foo bar");
or as an extension method if you prefer:
public static class StringExtensions { public static bool IsNullOrWhiteSpace(this string value) { if (value != null) { for (int i = 0; i < value.Length; i++) { if (!char.IsWhiteSpace(value[i])) { return false; } } } return true; } }
which allows you to use it directly:
bool isNullOrWhiteSpace = "foo bar".IsNullOrWhiteSpace();
For the extension method to work make sure that the namespace in which the StringExtensions static class has been defined is in scope.