I want to compare two char arrays to see if their contents are a palindrome.
static bool isPalindrome(string s)
{
char[] normal = s.ToCharArray();
char[] reversed = s.ToCharArray();
Array.Reverse(reversed);
return (normal == reversed) ? true : false;
}
The problem is that this method never returns true. Even when the arrays contains a palindrome.
What's wrong here?
Edit:
Answer: An array is a referense type. I compared the referenses, not the content.
Enumerable.SequenceEqual(normal, reversed);