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

What language is arduino?

735


what happens if you inherit multiple interfaces and they have conflicting method names?

669


Explain about WSDL

812


How to implement singleton design pattern in c#?

665


What is arraylist c#?

644


How do I stop my console from closing in c#?

656


Is array ienumerable c#?

661


What is Wrapper class in dot net?

822


Is stringbuilder better than string?

704


How will you allow a class to be inherited, but prevent the method from being over-ridden?

708


Why should I use interface in c#?

712


Define assert() method? How does it work?

826


What is the use of static in c#?

670


Are all methods virtual in c#?

716


Why c# is called c sharp?

648