I have made a simple function which checks if two words are an anagram by sorting and comparing the sorted values, however this program always returns true even if the words aren't anangrams. If I remove the .ToString() it evalutates as false. Any idea why it's doing this and any ideas on how to fix this?
public bool anagram(string word1, string word2)
{
char[] word1Arr = word1.ToArray();
char[] word2Arr = word2.ToArray();
Array.Sort(word1Arr);
Array.Sort(word2Arr);
Console.WriteLine(word1Arr);
Console.WriteLine(word2Arr);
if (word1Arr.ToString() == word2Arr.ToString())
{
return true;
}
else
{
return false;
}
}