Can somebody help me to run this program using c#. This program is to calculate the frequency of the number, for example 12 appear 10x. Before this I try to sort all list
Well, you could do this manually using a Dictionary:
var frequencies = new Dictionary();
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;
}
A simpler but less efficient approach would be to use 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);
}