Run loop form 0 to length of string
for ( int i = 0 ; i < str . Length ; i ++ ) { if ( map . ContainsKey ( str [ i ] ) ) map [ str [ i ] ] = map [ str [ i ] ] + 1 ; else map . Add ( str [ i ] , 1 ) ; }