航帆培训2026年国家·云南省公务员考试巅峰班

C#使用linq计算执行元素在列表中出现次数的方法
2015-04-20来源:易贤网

2025年事业单位联考系统精讲课程全新上线,包邮赠送配套纸质讲义资料,欢迎免费试看!>>

具体如下:

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

代码如下:

// Count the number of times an item appears in this list

public static int CountTimes<T>(this List<T> inputList, T searchItem)

{

return ((from t in inputList where t.Equals(searchItem) select t).Count());

}

更多信息请查看IT技术专栏

全年巅峰班 助你公考上岸

2026公务员·事业单位培训课程试听报名

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
推荐信息