Hi.......
This code is useful to check given string is palindrome or not.
Actually, there are some other way also to check palindrome.
So, be careful which code gives better efficiency.
You can comment the line-bool caseignore= str.Equals(revstr, StringComparison.OrdinalIgnoreCase);
and
in if condition you can use- if(string.Compare(str,revstr,true)==0)
Check String Is Palinrome Or Not
using System;
namespace palindromecheck
{
class Program
{
static void Main(string[] args)
{
string str, revstr;
Console.WriteLine("ASHISH Bolta Hai Enter Any String to Know It is Palindrome or not");
str = Console.ReadLine();
char[] tempstr = str.ToCharArray();
Array.Reverse(tempstr);
revstr = new string(tempstr);
bool caseignore= str.Equals(revstr, StringComparison.OrdinalIgnoreCase);
if (caseignore == true)
{
Console.WriteLine("ASHISH Bolta Hai "+str + " Is a Palindrome");
}
else
{
Console.WriteLine("ASHISH Bolta Hai " + str + " Is Not a Palindrome");
}
Console.Read();
}
}
}
vijaykrishnabor -7 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.