欢迎来到山村网

C#使用linq计算执行元素在列表中出现次数的方法

2019-03-02 11:57:25浏览:736 来源:山村网   
核心摘要:具体如下:这是使用linq计算元素在列表中出现的次数,调用方法非常简单,和sql语句很像代码如下:// Count the number of times a

具体如下:

这是使用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());
}
(责任编辑:豆豆)
下一篇:

C#使用自定义算法对数组进行反转操作的方法

上一篇:

PHPstorm8 自动换行设置方法

  • 信息二维码

    手机看新闻

  • 分享到
打赏
免责声明
• 
本文仅代表作者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,作者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们 xfptx@outlook.com