C# How To Check if a String Is a Palindrome
Palindrome Check
A palindrome is a word that is the same forward and backward, like "level". Reverse the word, and compare it with the original:
Example
string text = "level";
char[] chars = text.ToCharArray();
Array.Reverse(chars);
string reversed = new string(chars);
if (text == reversed)
{
Console.WriteLine(text + " is a palindrome");
}
else
{
Console.WriteLine(text + " is not a palindrome");
}
Explanation:reversed holds the characters of text in the opposite order.
If both strings are equal, the word is a palindrome.