Pages

Men

rh

6/10/2012

Checking Given Number is Polindrome or not?


Public void ChkGivenNumberIsPolindromeOrNot()
{
  bool BL = IsPalindrome(textBox2.Text, StringComparison.OrdinalIgnoreCase);
    if (BL == true)
   {
      MessageBox.Show("This is Polindrome");
   }  
      else
     {
       MessageBox.Show("This is not Polindrome");
   }
 }
public bool IsPalindrome(string str, StringComparison comparisonType)
           {
             bool valid = true;
             int halfway = str.Length / 2;
             int lastIndex = str.Length - 1;
             for (int i = 0; i < halfway; i++)
             {
                 if (!str.Substring(i, 1).Equals(str.Substring(lastIndex - i, 1), comparisonType))
                 {
                    valid = false;
                    break;
                 }
             }
            return valid;
          }















No comments :

Post a Comment