To check if a string is palindrome or not

bool IsPalindrome (string CheckString)
{
if (CheckString == null || CheckString.Length == 0)
{
return false;
}
for (int i = 0; i < CheckString.Length / 2; i++)
{
if (CheckString[i] != CheckString[CheckString.Length - 1 - i])
{
return false;
}
}
return true;
}

If the function above returns true, the string you passed is a palindrome.


Comments

Author: Venkatesan Prabu .J09 Jun 2008 Member Level: Gold   Points : 1



Provide some explanation for your code snippet.

Regards,
Venkatesan Prabu . J

Author: shyamalendu prusty23 Jun 2008 Member Level: Silver   Points : 1

Palindrome check is required to know whether the word entered is a palindrom or not?

e.g.

Some men interpret nine memos



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: