3 ms·
IsNullOrWhiteSpace() was added in dot net 4: http://msdn.microsoft.com/en-us/library/system.string.isnullorwhitespace(v=vs.110).aspx http://msdn.microsoft.com/e
by ColinDabritz 12y ago
IsNullOrWhiteSpace() was added in dot net 4:
http://msdn.microsoft.com/en-us/library/system.string.isnullorwhitespace(v=vs.110).aspx http://msdn.microsoft.com/en-us/library/system.string.isnull...
I agree that Truncate would be a nice one to include in the core.
- Someone1234 12y ago> IsNullOrWhiteSpace() was added in dot net 4: Look at what the helper actually does. I already addressed this in my comment. string hello = magic(); if(hello.IsNullOrWhiteSpace()) { ... } Is significantly more intuitive than: string hello = magic(); if(string.IsNullOrWhiteSpace(hello)) { ... } Plus it is consistent with things like Contains("XYZ") (e.g. hello.Contains("something")). Truncate is useful just because Substring() throws a bunch of dumb exceptions. It is mostly a workaround for Substring's poor design.
- deleted 12y ago[deleted]
- eogas 12y agoThat defeats half the purpose though, because if the string is null, you won't be able to call the method without throwing an exception. Or is that not the case for extension methods?
- ygra 12y agoExtension methods are rewritten by the compiler to a normal static method call with the subject as their first argument (that's how they're defined, anyway). And since you can legitimately pass null to those methods there will be no NRE by default.