Ну, вы можете сделать это вручную, используя Dictionary<int, int>
:
var frequencies = new Dictionary<int, int>();
foreach (var item in data)
{
int currentCount;
// We don't care about the return value here, as if it's false that'll
// leave currentCount as 0, which is what we want
frequencies.TryGetValue(item, out currentCount);
frequencies[item] = currentCount + 1;
}
Более простой, но менее эффективный подход - использовать LINQ:
var frequencies = data.ToLookup(x => x) // Or use GroupBy. Equivalent here...
.Select(x => new { Value = x.Key, Count = x.Count() })
.ToList();
foreach (var frequency in frequencies)
{
Console.WriteLine("{0} - {1}", frequency.Value, frequency.Count);
}