C# - Program to check if a Text is Palindrome or not


C# - Program to check if a Text is Palindrome or not

CODE
using System; class Program { public static void Main() { bool result = true; string text = "Malayalam"; //Palindrome is a string that reads same backward and forward. text = text.ToLower(); //Check only half the length of the text. for (int i = 0, j = text.Length - 1; i < text.Length / 2; i++, j--) { if (text[i] != text[j]) { result = false; break; } } if(result) Console.WriteLine("The text [{0}] is a palindrome", text); else Console.WriteLine("The text [{0}] is not a palindrome", text); //Malayalam returns true //English returns false Console.ReadKey(); } }

Comments