Simple and typical C# test project when we have to create a palindrome recognizer program. A palindrome word or sentence is readable backward as well and we get the same sentence. e.g. "step on no pets" In this task we have to work with only alphabetic characters so if the input contains any others then we need to ignore them.
The method is the following:
public static bool IsPalindrome(string str)
{
char[] c = str.ToCharArray();
string filtered_string = null;
foreach (char ch in c)
{
int code = ch;
//Only alphabetical characters
if ((code > 97) && (code < 122)) filtered_string += ch;
}
c = filtered_string.ToCharArray();
//Reverse method on the array
Array.Reverse(c);
string str_reverse = new string(c);
if (str_reverse == str) return true;
return false;
}