Pro_Unit

CountCharaqctes

Sep 24th, 2022
1,248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.44 KB | None | 0 0
  1. public static Dictionary<char, int> Count(string value)
  2. {
  3.     var dictionary = new Dictionary<char, int>();
  4.        
  5.     char[] chars = value.ToCharArray();
  6.        
  7.     for (int i = 0; i < chars.Length; i++)
  8.     {
  9.         if (dictionary.ContainsKey(chars[i]))
  10.         {
  11.             dictionary[chars[i]]++;
  12.         }
  13.         else
  14.         {
  15.             dictionary.Add(chars[i], 1);
  16.         }
  17.     }
  18.        
  19.     return dictionary;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment