Tag Archives: LINQ

Partitioning the collection using LINQ: different approaches, different performance, the same result

Another blog post inspired by StackOverflow question. This time it’s all about LINQ, performance and a tiny little detail, that really matters. The question itself is about yield keyword in VB.NET, but there is another, much more interesting part I’d like to examine. The algorithm quoted in the question is the key.

The idea is simple. How to partition a collection into parts with given number of elements in ever part? Algorithm presented in the question is as easy as the questions seems to be:
Continue reading Partitioning the collection using LINQ: different approaches, different performance, the same result

Why (or when) you should/shouldn’t use Descendants() method

A lot of LINQ to XML questions on StackOverflow are being answered using Descendants() method calls. It looks like most of people think it’s the best way to handle and query XML document: it’s easy to use, you don’t have to worry about whole tree structure. It just works. But are these solutions really good ones? Is Descendants() method really that good as it seems to be? I would say: NO! I think common LINQ to XML queries should not use Descendants(). I’ll try to answer it shouldn’t be used in this blog post.
Continue reading Why (or when) you should/shouldn’t use Descendants() method

Querying hierarchical data using LINQ to Object

Another blog post in response to a StackOverflow question. It’s about LINQ again, but it’s no as low-level as the one from previous post. This time the question is quite simple: How to search Hierarchical Data with Linq.

To answer the question, let’s start with some sample data we could fight against, starting with Person class:
Continue reading Querying hierarchical data using LINQ to Object

Did you know about that LINQ feature? I guess you didn’t!

First of all, I have to say thank you! to Toto for Most optimized use of multiple Where statements StackOverflow question and hatchet for really great answer, which made me write this blog post.

The question is simple: does LINQ optimize multiple Where calls? I think most people would say no. I did say no too! Google says no * unless you dig really deep! But what is the correct answer to that question? Continue reading Did you know about that LINQ feature? I guess you didn’t!