Skip to content
Advertisements

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

Advertisements

Deependra Kushwah View All

Deependra is a Senior Developer with Microsoft technologies, currently working with Opteamix India business private solution. In My Free time, I write blogs and make technical youtube videos. Having the good understanding of Service-oriented architect, Designing microservices using domain driven design.

What you think

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: