I\'m sure I\'ve missed something here. With a certain project I need to check if a string is empty or null.
Is there an easier way of writing this?
i
if (string.IsNullOrEmpty(myString)) {
...
}
Or you could take advantage of a quirk in extension methods, they allow this to be null:
static class Extensions {
public static bool IsEmpty(this string s) {
return string.IsNullOrEmpty(s);
}
}
which then lets you write:
if (myString.IsEmpty()) {
...
}
Although you probably should pick another name than 'empty'.