Check for palindrome in c#

Palindrome. Palindromes can be read in both directions. A palindrome has the same letters on both ends of the string.

using System;


namespace Demo
{
	public class Program
	{

		///
		/// Check whether the string is a palindrome.
		///
		public static bool IsPalindrome(string value)
		{
			int min = 0;
			int max = value.Length - 1;
			while (true)
			{
				if (min > max)
				{
					return true;
				}
				char a = value[min];
				char b = value[max];
				if (char.ToLower(a) != char.ToLower(b))
				{
					return false;
				}
				min++;
				max--;
			}
		}

	public static void Main()
	{
	    foreach (string value in new[] { "aba", "bba", "NaN" })
	    {
	    Console.WriteLine("{0} = {1}", value, IsPalindrome(value));
	    }
	}
   }
}

 

 

OutPut

aba=true

bba=false

NaN=true

Close

About The Author

Deependra Kushwah
Deependra kushwah is a member of the fastest growing bloggers community "betechnical", Author, Youtuber, and hardcore Coder. I love writing code in different languages, I also write blogs on tech tutorials, gadgets review and also post some technical videos on youtube on many topics.

This site uses Akismet to reduce spam. Learn how your comment data is processed.