Last post Dec 16, 2008 05:42 PM by worldspawn
Dec 15, 2008 04:20 PM|JByrd2007|LINK
I'd like to see a static method added to the List<T> (and possibly other controls) that returns a boolean value representing whether the List<T> instance is null or empty. I created a helper method like this myself that checks to see if the list passed to
it is null or has no elements inside:
Ideally, it would be nice to have something that tests to see if the List<T> is equivalent to default(List<T>) as well.
Hope this helps!
Dec 15, 2008 08:12 PM|worldspawn|LINK
This is why we have extension methods:
public static class MyClass
public static bool IsNullOrEmpty(this List list)
return list == null || list.Count == 0;
Dec 16, 2008 02:17 PM|JByrd2007|LINK
I understand that an extension method would provide this, but that means that everyone needing this would have to write the same method, which is why I think it should be added as a standard library function (isn't that what libraries are for -- preventing
us all from rewriting the same code? [:)]).
Dec 16, 2008 05:42 PM|worldspawn|LINK
Hmm I suppose thats true. I didn't notice this was in the feature requests section :)
Libs should only go so far, you could write a bunch of extension methods and put them up on codeplex. Infact that's exactly what a lot of people are already doing.