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!!
0 Comments:
Post a Comment
<< Home