计算集合的频率分布与.net / C# [英] Calculating frequency distribution of a collection with .Net/C#

查看:391
本文介绍了计算集合的频率分布与.net / C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个快速/简单的方法来计算的.Net集合使用LINQ或频数分布?

Is there a fast/simple way to calculate the frequency distribution of a .Net collection using Linq or otherwise?

例如:一个任意长的列表中包含许多重复。什么是走在列表和计数/跟踪重复一个聪明的方法?

For example: An arbitrarily long List contains many repetitions. What's a clever way of walking the list and counting/tracking repetitions?

推荐答案

最简单的方法是使用一个HashMap,要么使用值作为重点,并增加了价值,或者选择一个桶大小(桶1 = 1 - 10 ,斗2 = 11 - 20等),并递增每桶由值

The easiest way is to use a hashmap and either use the value as the key and increment the value, or pick a bucket size (bucket 1 = 1 - 10, bucket 2 = 11 - 20, etc), and increment each bucket by the value.

然后就可以通过并确定的频率。

Then you can go through and determine the frequencies.

这篇关于计算集合的频率分布与.net / C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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