My array is A = {2, 3, 4, 3, 4, 2, 4, 2, 4}
I need an array B that stock at the index i
the number of occurences of i
in the a
If you want to find out how many time each item presents in the, say, array, you can use Linq:
int[] a = new int[]
{ 2, 3, 4, 3, 4, 2, 4, 2, 4 };
// I'd rather not used array, as you suggested, but dictionary
Dictionary b = a
.GroupBy(item => item)
.ToDictionary(item => item.Key, item => item.Count());
...
the outcome is
b[2] == 3;
b[3] == 2;
b[4] == 4;