I have an array, and I want to count the number of instances it appears.
Example input:
int[] a = new int[]{1,1,1,2,3,4,4};
output:
1 3
2 1
3 1
4 2
So far I am able to get the distinct but can't get the count.
public static void arrayfrequency(int[] a)
{
//store the distinct list
var GetDistinct = a.Distinct().ToArray();
foreach (int index in GetDistinct)
{
Console.WriteLine(index);
}
}