using System;
using System.Collections.Generic;
class MainClass {
public 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.ReadKey();
}
}
Is there a way I can make this code that counts the number of duplicate values in an array work for strings, I need it to output something like:
Donald - 2 James - 1
The numbers being the amount of times it has been repeated in the string