Dot Net Capsules

A Capsule on .NET, everyday, keeps you .NetHealthy!!!!

My Photo

Programmer. Visit my new blog at

Friday, March 20, 2009

Checking an item is there in the array or not using LINQ

If you want to check whether an item is there in an array then you can use Linq instead of looping through the array.

Here is the sample code:

string[] selectedItems = items.Split(',');
int count = selectedItems.Count(s => s == id.ToString());

This code gives us the number of times the 'id' is there in the 'selectedItems' array.

You can find more Linq one liners here(


Labels: , ,


Post a Comment

<< Home

You Visitor Number:
Free Web Site Counter
Free Counter
free counters