[英]Get Count of an Item of Generic List
我有一個int List<int>()
的通用列表,我想知道它的一個項目的Count。 我該怎么做?
使用擴展方法是最簡單的方法
int count = list.Count(i => i > 10);// get the count of those which is bigger than 10
如果要計算列表中項目數的計數,可以使用表達式執行此操作:
int count = myList.Count(i => i.Equals(5));
通用列表的計數(從存儲過程生成)
List<GetDivisionsForGroup> GroupDivision = new List<GetDivisionsForGroup>();
String storedProcedures = "Sp_GetDivisionsForGroup " + grpid;
GroupDivision = db.ExecuteStoreQuery<GetDivisionsForGroup>("exec " + storedProcedures).ToList();
if (GroupDivision.Count > 0)
{
}
http://code.msdn.microsoft.com/LINQ-Aggregate-Operators-c51b3869
public void Linq73()
{
int[] factorsOf300 = { 2, 2, 3, 5, 5 };
int uniqueFactors = factorsOf300.Distinct().Count();
Console.WriteLine("There are {0} unique factors of 300.", uniqueFactors);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.