How to Write a Palindrome Program in C#?

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest

Palindrome. Palindromes can be read in both directions. In simple terms, a palindrome has the same letters on both ends of the string. For a better understanding, go through this example of palindrome program in C#.

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

 

So, did this article serve your purpose? Share your comments and concerns in the comment section below.

[yikes-mailchimp form=”1″]

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on whatsapp
Share on email
Author Bio

Leave a Reply

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

Recommended for you
Connect With Us
Stay Connected

Subscribe to our newsletter today to receive updates on latest tech news, tutorials SEO tips many more.

Latest Articles

Free hub for guest blogging nerds and newbie writers

  • Submit Guest Post
  • Share your Knowledge
  • Build your Backlinks
  • Advertise your products
  • Make money by writing
Subscribe to our newsletter today to receive updates on latest tech news, tutorials SEO tips many more.