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(stringstr, StringComparison comparisonType)
{ boolvalid = true;
inthalfway = str.Length / 2;
intlastIndex = 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;
}
}
returnvalid;
}
No comments:
Post a Comment