Skip to content

Instantly share code, notes, and snippets.

@jmsevold
Last active May 29, 2016 03:36
Show Gist options
  • Save jmsevold/be2e51d1d76d8b7e221fd362c3f2b588 to your computer and use it in GitHub Desktop.
Save jmsevold/be2e51d1d76d8b7e221fd362c3f2b588 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System;
public class Program
{
public static void Main()
{
int[] nums = new int[] {1,1,1,2,2,3};
Dictionary<string,int> numCount = new Dictionary<string,int>();
foreach(int num in nums)
{
string numKey = num.ToString();
if(numCount.ContainsKey(numKey))
{
numCount[numKey] += 1;
}
else
{
numCount.Add(numKey,1);
}
}
foreach(KeyValuePair<string,int> pair in numCount)
{
Console.WriteLine("{0}, {1}", pair.Key, pair.Value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment