Showing posts with label linq. Show all posts
Showing posts with label linq. Show all posts

Monday, February 1, 2010

How to get an indexed item of an IEnumerable object (Linq)

How to get an indexed item of an IEnumerable object (Linq), this is a question which I often have had when I start using IEnumerable. But it is possible with the ElementAt() extension method!.

Tuesday, October 13, 2009

Tip: Linq to SQL

When you are using Linq to SQL, you have to read (and use) these tips.
I mostly use Linq to Objects, but when I am going to use Linq to Sql is will read these tips again:)

Thursday, June 25, 2009

LINQ: Join

The Join operator is an extension method for the String object. With this you can easily create a comma separated string of a list from strings.

On Erwin's Blog you can read an example.

Tuesday, June 9, 2009

LINQ: Debug Visualizer

On the blog of Scottgu you will find some instructions for installing a Linq to SQL debug visualizer. With this visualizer installer you can see the relating SQL queries for the Linq statements.

Thursday, May 7, 2009

LINQ: Any() or Count()

Update 1 july: Also information about the ToDictionary method

When you have a collection and you want to check if there are items in the collection you can do this

Codefragment 1:

if (lCollection.Count() > 0) {
// do something
}


Codefragment 2:

if (lCollection.Any()) {
// do something
}


When the collection is also an ICollection the Count property is returned otherwise the collection is enumerated an counted for each element. The last one is an expensive operation.

The Any() method begins to iterate over the collection and stops when the condition is true. If you use the variant without the condition, the method iterates over the first element and stops. So code fragment 2 is a better solution qua performance.