using System.Collections.Generic;
public static void Main()
Console.WriteLine(anagramChecker("test", "test"));
Console.WriteLine(anagramChecker("test", "tests"));
Console.WriteLine(anagramChecker("test", "tess"));
Console.WriteLine(anagramChecker("test", "stet"));
Console.WriteLine(anagramChecker("test", "tes"));
Console.WriteLine(anagramChecker("", ""));
private static bool anagramChecker(string s1, string s2)
if (String.IsNullOrEmpty(s1) || String.IsNullOrEmpty(s2))
if (s1.Length != s2.Length)
Dictionary<char, int> s1Chars = getCharDictionary(s1);
Dictionary<char, int> s2Chars = getCharDictionary(s2);
for (int i = 0; i<s1Chars.Keys.Count; i++)
currentChar = s1Chars.ElementAt(i).Key;
if (!containsChar(currentChar, s1Chars[currentChar], s2Chars))
private static Dictionary<char, int> getCharDictionary(string val)
Dictionary<char, int> temp = new Dictionary<char, int>();
char[] chars = val.ToCharArray();
for (int i = 0; i<chars.Length; i++)
if (temp.ContainsKey(currentChar))
for (int y = i+1; y < chars.Length; y++)
if (chars[y].Equals(currentChar))
temp.Add(currentChar, numFound);
private static bool containsChar(char val, int numTimes, Dictionary<char, int> chars)
return (chars.ContainsKey((val)) && chars[val] == numTimes);