Finding the maximum value from the map
int currentMax = 0 ; char arg_max = ( char ) 0 ; foreach ( KeyValuePair < char , int > it in occ ) { if ( it . Value > currentMax || ( it . Value == currentMax && it . Key > arg_max ) ) { arg_max = it . Key ; currentMax = it . Value ; } }