Dot Net Capsules
A Capsule on .NET, everyday, keeps you .NetHealthy!!!!
About Me

- Name: Ashish Sheth
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
Wednesday, April 29, 2009
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!!
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!!
