Dot Net Capsules

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

My Photo
Name:

Co-founder at mymoneysage.in Result oriented Tech Leader Programmer, Sotware Architect, Techologist Polyglot software developer, expert in multiple tech stack Specialties: Machine learning, Artificial intelligence, Conversational Interface, RASA, AWS, Lex, REST, GraphQL, PWA, C#, .NET, ASP.NET, XML, Web services, Agile, SCRUM

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.

Update:
You can find more Linq one liners here(http://www.informit.com/guides/content.aspx?g=dotnet&seqNum=691):


Enjoy!!

Labels: , ,

0 Comments:

Post a Comment

<< Home

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