Storing frequencies
Dictionary < int , int > m = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < b . Length ; i ++ ) m [ b [ i ] ] = 0 ; for ( int i = 0 ; i < b . Length ; i ++ ) { m [ b [ i ] ] ++ ; } List < int > v = new List < int > ( ) ; foreach ( KeyValuePair < int , int > i in m ) { v . Add ( i . Value ) ; }