Check String Is Palinrome Or Not

ashishkumar008 0 Tallied Votes 284 Views Share

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);
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();
            revstr = new string(tempstr);

            bool caseignore= str.Equals(revstr, StringComparison.OrdinalIgnoreCase);

            if (caseignore == true)
                Console.WriteLine("ASHISH Bolta Hai "+str + " Is a Palindrome");
                Console.WriteLine("ASHISH Bolta Hai " + str + " Is Not a Palindrome");