Write code for palindrome?

Answer Posted / dadi

static void checkPalindrome()
{
Console.WriteLine("please enter a string");
string str = Console.ReadLine();
bool isPalindrome = true;
int count = str.Length;
for (int i = 0; i < count / 2; i++)
{
if (str[i] != str[count - i - 1])
{//check char[0]==char[n-1], char[1]== char[n-2] and so on......
isPalindrome = false;
break;
}
}
Console.WriteLine("entered string {0} is {1} palindrome", str, (isPalindrome) ? "a" : "not a");
Console.Read();
}

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Should I use double or float?

502


How can you sort strings in array that are passed to method as arguments?

532


What is .net console?

535


Is double a decimal?

520


Explain About friend and Protected friend

523






What is ulong in c#?

575


Why constructor is used in c#?

489


What Is The Smallest Unit Of Execution In .net?

526


Why do we need serialization?

440


What is the difference between finalize() and dispose()?

495


How many constructors can a class have c#?

472


What is difference between property and variable in c#?

469


What is interface used in c#?

585


What is the correct way of declaring an xml namespace?

472


What is an interface class? Give one example of it

482