We can do it in two ways
a) By using inbuild functions
string strRev,strReal = null;
Console.WriteLine("Enter the string..");
strReal = Console.ReadLine();
char[] tmpChar = strReal.ToCharArray();
Array.Reverse(tmpChar);
strRev=new string(tmpChar);
if(strReal.Equals(strRev, StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("The string is pallindrome");
}
else
{
Console.WriteLine("The string is not pallindrome");
}
Console.ReadLine();
Ref : http://www.codeproject.com/Tips/153399/To-check-string-is-palindrome-or-not-in-NET-C
b)Without Using inbuild functions
When i write the first program, the interviewer asked me to write the same by not using inbuild functions
private static bool chkPallindrome(string strVal)
{
try
{
int min = 0;
int max = strVal.Length - 1;
while (true)
{
if (min > max)
return true;
char minChar = strVal[min];
char maxChar = strVal[max];
if (char.ToLower(minChar) != char.ToLower(maxChar))
{
return false;
}
min++;
max--;
}
}
catch (Exception)
{
throw;
}
}
Ref : You can find out more here http://www.dotnetperls.com/palindrome