using System.Text.RegularExpressions;
public static void Main()
Console.WriteLine("Anagram check: provide 2 words or q to quit:");
var input = Console.ReadLine();
Console.WriteLine($"Error; You need to provide 2 words.");
if (input.ToLower() == "q") break;
string[] words = Regex.Split(input, @"[^a-zA-Z]+");
Console.WriteLine($"Error; You need to provide 2 words.");
Console.WriteLine($"Is word <{words[0]}> an anagram for word <{words[1]}>: {IsAnagram(words[0].ToLower(), words[1].ToLower())}");
private static bool IsAnagram(string w1, string w2)
if (w1.Length != w2.Length) return false;
var frequency1 = new int[30];
var frequency2 = new int[30];
foreach (var letter in w1)
frequency1[letter - 'a']++;
foreach (var letter in w2)
frequency2[letter - 'a']++;
return frequency1.SequenceEqual(frequency2);