News

In LINQ, Don't Use Count() When You Mean Any()

Author: Craig Stuntz If you have a list, array, or query in a C#/LINQ application and need to check and see if the list is empty, the correct way to do this is to use the Any() extension method: if (q.Any()) { Similarly, you can check to see if any elements in the list meet a certain condition: if (q.Any(i => i.IsSpecial)) { If the query provider is something like LINQ to Entities…
Read more
News

In LINQ, Beware of Skip(0)

Author: Marc Geldon Calling IQueryable<T>.Skip(0) seems like it should be “free.” In other words, since it will have no effect on the resulting data, there should be little to no performance cost for calling it. But this is demonstrably not true in LINQ to…