Checking For Empty Enumerations

Posted on Dot net Slackers See other posts from Dot net Slackers
Published on Thu, 10 Jun 2010 00:00:00 GMT Indexed on 2010/06/10 9:23 UTC
Read the original article Hit count: 220

Filed under:
While spelunking in some code recently I saw a method that looked something like this: public void Foo<T>(IEnumerable<T> items) { if(items == null || items.Count() == 0) { // Warn about emptiness } } This method accepts a generic enumeration and then proceeds to check if the enumeration is null or empty. Do you see the potential problem with this code? Ill give you a hint, its this line: items.Count() == 0 Whats the problem? Well that line right there has the potential...

Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.



Email this Article

© Dot net Slackers or respective owner