这是使用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()); }
这是使用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()); }