ITPub博客

首页 > 应用开发 > IT综合 > c#使用linq计算元素在列表中出现的次数

c#使用linq计算元素在列表中出现的次数

原创 IT综合 作者:mabiyaya1 时间:2015-04-07 09:06:54 0 删除 编辑

使用linq计算元素在列表中出现的次数,调用方法非常简单,和sql语句很像

//计算的次数一个项目出现在这个列表
public static int CountTimes(this List inputList, T searchItem)
{
return ((from t in inputList where t.Equals(searchItem) select t).Count());
}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30189795/viewspace-1516927/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2015-04-03

  • 博文量
    2
  • 访问量
    3530