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

Are structs value types or reference types?

566


Can partial class be inherited?

497


What is stringreader in c#?

483


How do you specify a custom attribute for the entire assembly (rather than for a class)?

523


What do you mean by streamreader/streamwriter class in c#?

522






What's the difference between an integer and int?

530


What is the different types of private assembly and shared assembly?

497


Describe the types of comments in c#?

504


Can constructor have return type c#?

634


What is delegation in oops?

516


What is difference between hashtable and dictionary in c#?

489


What is yield c#?

495


What is the use of table aliases?

488


What is console writeline in c#?

469


What's new in c#?

483