public static bool IsPalindrome(string s)
{
int iLength, iHalfLen;
iLength = s.Length - 1;
iHalfLen = iLength / 2;
for (int i = 0; i <= iHalfLen; i++)
{
if (s.Substring(i, 1) !=
s.Substring(iLength - i, 1))
{
return false;
}
}
return true;
}
static void Main(string[] args)
{
Console.WriteLine("\nPalindromes?");
string[] sa = new string[]{
"level", "minim", "radar",
"foobar", "rotor", "banana"};
foreach (string v in sa)
Console.WriteLine("{0}\t{1}",
v, StringEx.IsPalindrome(v));
}
OUTPUT
Palindromes?
level True
minim True
radar True
foobar False
rotor True
banana False