To store string which has maximum frequency
string s = " " ; foreach ( KeyValuePair < string , int > i in m ) { if ( i . Value > maxi ) { maxi = i . Value ; s = i . Key ; } else if ( i . Value == maxi ) { string ss = i . Key ; if ( ss . Length > s . Length ) s = ss ; } }