Valid Anagram in C#

Run Settings
LanguageC#
Language Version
Run Command
using System; using System.Collections.Generic; using System.Linq; class MainClass { static void Main() { Console.WriteLine("Enter first string:"); string str1 = "super"; Console.WriteLine("Enter second string:"); string str2 = "repus"; if (AreAnagrams(str1, str2)) Console.WriteLine("The strings are anagrams."); else Console.WriteLine("The strings are NOT anagrams."); } static bool AreAnagrams(string str1, string str2) { if (str1.Length != str2.Length) return false; Dictionary<char, int> charCount = new Dictionary<char, int>(); foreach (char ch in str1) { if (charCount.ContainsKey(ch)) { charCount[ch]++; } else { charCount[ch] = 1; } } foreach (char ch in str2) { if (!charCount.ContainsKey(ch) || charCount[ch] == 0) return false; charCount[ch]--; } return true; } }
Editor Settings
Theme
Key bindings
Full width
Lines