不同价值的计数 [英] count of distinct values

查看:83
本文介绍了不同价值的计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在共享点列表中有一列具有重复值.我想获取每个不同值的计数,并按计数降序将其显示为报告.

I have a column in sharepoint list with repititive values. I want to get the count of each distinct value and display it as a report in the descending order of count.

推荐答案

如果使用的是.Net 3.0(或更高版本) ),请使用LINQ.

此处 [
If you are using .Net 3.0 (or higher), use LINQ.

There are some good count samples here[^]. Check if any of them suits you (the count by group one specifically).

If you post some code here, members would be able to provide more details on how you should go about your solution.


如果您不使用LINQ,则可以只使用字典为此.

例如

If you''re not using LINQ, you could just use a dictionary to do such.

Ex.

Dictionary<string, int> dict = new Dictionary<string, int>();
int intCount;
 
foreach (string strValue in values)
{
  if (dict.TryGetValue(strValue, out intCount))
    dict[strValue] = ++intCount;
  else
    dict[strValue] = 1;
}



诸如此类...完成后,字典将具有所有唯一值作为键以及值部分中每个键的计数.



Something like that...after you''re done, the dictionary will have all the unique values as keys and the counts of how many for each in the value portion.


这篇关于不同价值的计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆