0

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)

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();
        }

        
    }
}
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by vijaykrishnabor
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.