根据ID计算列表项 [英] Count list item based on ID
本文介绍了根据ID计算列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想找到List<>基于过滤器的项目,比如
基于 ID 赞
1 a ajay
1 b rubi
3 c rakhi
3 d reshi
3 f rail
输出
应该是
从表中选择计数,其中id = 1
O / p = 2
其中id = 3
在LINQ中O / P = 3
我们如何实施。
谢谢。
我尝试了什么:
没什么
解决方案
IEnumerable有一个计数扩展,它带有一个func< tsource,bool>参数,这就像
int count = table.Count(rec => rec .id == 1 );
使用位置:
List< string> data = new 列表< string>(){ hello有, 再见, whoo there};
var filtered = data.Where(s = > s.Contains( ot));返回仅包含第一个和最后一个字符串的枚举。
i want to find List<> item based on filter like where
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
解决方案
IEnumerable has a count extension that takes a func<tsource,bool> parameter, so this becomes as simple as
int count = table.Count(rec=>rec.id == 1);
Use Where:
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.
这篇关于根据ID计算列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文