Skip to main content

Palindrome Words in C#

How to determine if given word is palindrome


Palindrome is a word that spells same both backward or forward

lets have a method the returns true or false based on the status of the word whether palindrome or not

public bool IsPalindrome(string words)
{
     //declare a variable named reverse and set it to empty string
    string reverse=string.Empty;
    for (var index=words.Length-1,index >=0;index--)
   {
        reverse +=words[index].ToString();
    }
    if(reverse == words)
      return true;
     else
         return false;
 }
 static void Main(string[] args)
{
   Console.WriteLine("Enter a word");
   string words=Console.ReadLine();
   var isPolindrome=IsPalindrome(words);
   if (isPolindrome)
   {
       Console.WriteLine("The  word {0} is Palindrome",words);
   }
   else
   Console.WriteLine("The word {0} is not Palindrome",words)
}

Comments

Post a Comment