What is palindrome String?
"Palindrome string is a string that remains the same when its chars are reversed"
Example:
string 'wowow' is a palindrome string.
string 'dotnetmirror'- it not a palindrome string.
Snippet
using System;
class PalindromeString
{
static bool CheckPalindrome(string CheckString)
{
if (CheckString == null || CheckString.Length == 0)
{
return false;
}
int strMaxIndex = CheckString.Length - 1;
for (int i = 0; i < CheckString.Length / 2; i++)
{
if (CheckString[i] != CheckString[strMaxIndex - i])
{
return false;
}
}
return true;
}
public static void Main()
{
Console.WriteLine("********** Palindrome string Check Example ********");
Console.WriteLine();
Console.Write("Enter string to you want to check: ");
string str = Console.ReadLine();
if (CheckPalindrome(str))
{
Console.WriteLine("{0} is a Palindrome String", str);
}
else
{
Console.WriteLine("{0} is not a Palindrome String", str);
}
Console.ReadLine();
}
}
Output:
Example1 : Input =wowow (palindrome string)
Example2 : Input =dotnetmirror (not a palindrome string)
Example3 : Input =maddam(palindrome string)