static void Main(string[] args)
{
int[] array = { 1, 2, 3, 4, 1, 2, 3, 4, 5 };
var dict = new Dictionary
foreach (var value in array)
{
if (dict.ContainsKey(value))
{
dict[value]++;
}
else dict[value] = 1;
}
foreach (var pair in dict)
Console.WriteLine("Value {0} occurred {1} times", pair.Key, pair.Value);
Console.ReadKey();
}
No comments:
Post a Comment