Skip to content

Instantly share code, notes, and snippets.

@cagataycali
Created April 27, 2016 00:20
Show Gist options
  • Save cagataycali/86fba995edbd2e928c14cc9ea06ad33d to your computer and use it in GitHub Desktop.
Save cagataycali/86fba995edbd2e928c14cc9ea06ad33d to your computer and use it in GitHub Desktop.
using System.Linq;
static void Main(string[] args)
{
int[] array = { 10, 5, 10, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 11, 12, 12 };
var dict = new Dictionary<int, int>();
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.WriteLine(dict.Values.Max());
foreach (var item in dict)
{
if ( dict.Values.Max() == item.Value)
{
Console.WriteLine("This is max val {0}",item);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment