Category Archives: Linq

LINQ – the order of elements when using Where()

Last week I was asked if the order of elements found using a where clause was guaranteed to be the same as the order of the original collection. That question is hard to answer. In the normal case (where nobody has overwritten … Continue reading

Posted in C#, Linq | Tagged , , , , , , | Leave a comment

LINQ and iterating over null collections.

Ok, todays title is weird, but I have come up with a little hack, that will make the code easier to read (sometimes). At work we have some pretty clear specifications, that says how to fill out some properties in … Continue reading

Posted in C#, Linq | Tagged , , , , | Leave a comment

LINQ and counting

When we work with collections we often have to count the elements in some way. Sometimes we need to know how many elements there are or how many elements that  complies with some  condition. So let’s assume that I have … Continue reading

Posted in C#, Linq | Tagged , , , , , | 2 Comments

Performance of Skip and Take in Linq to Objects

Note: This is not relevant for Linq to Sql or Entity framework, where Skip and Take are transalted into their SQL equivalents. This week I had to write some code where some 500.000 objects in a collection had to chopped … Continue reading

Posted in C#, Linq | Tagged , , , | 1 Comment