Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to find List<> item based on filter like where

SQL
Based on ID Like 
1     a    ajay
1     b    rubi
3     c    rakhi
3     d    reshi
3     f    rail


output
should be
select count from table where id=1
O/p= 2
where id=3
O/P=3

in LINQ how we can implement.

Thanks.

What I have tried:

Nothing
Posted
Updated 9-Nov-16 16:58pm
v3
Comments
Karthik_Mahalingam 9-Nov-16 8:14am    
Not clear, use improve question to add more info.

IEnumerable has a count extension that takes a func<tsource,bool> parameter, so this becomes as simple as
C#
int count = table.Count(rec=>rec.id == 1);
 
Share this answer
 
Comments
Member 11449483 10-Nov-16 1:43am    
Thanks.
Use Where:
C#
List<string> data = new List<string>() { "hello there", "goodbye", "whoo there" };
var filtered = data.Where(s => s.Contains("o t"));
Returns an enumerable with the first and last strings only.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900