I'm looking to output the number of duplicates for each int in an array e.g. the array 1,2,3,4,1,1,3 would output 1:3, 2:1, 3:2, 4:1. at the moment no matter how many of each number there is the dictionary only counts one and outputs every value to be 1.
static void Main(string[] args)
{
Console.WriteLine("Type 10 numbers");
int[] arr1 = new int[10];
for (int i = 0; i < arr1.Length; i++)
{
arr1[i] = Convert.ToInt32(Console.ReadLine());
}
output(arr1);
Console.ReadKey();
}
static void output(int[] arr1)
{
Dictionary<int, int> dict = new Dictionary<int, int>();
for (int i =0; i < arr1.Length; i++)
{
if (dict.ContainsKey(arr1[i]))
{
int c = dict[arr1[i]];
dict[arr1[i]] = c++;
}
else
{
dict.Add(arr1[i], 1);
}
}
for (int i =0; i<arr1.Length; i++)
{
Console.WriteLine(arr1[i] + ":" + dict[arr1[i]]);
}
}