Function to check whether the Provided string is Palindrome or Not

Posted by Neeks under C# category on | Views : 3860
This function will return true if the Provided string is Palindrome.
Benefit for this function is that this function does not execute the loop as per the string length.
Loop is executed for the Half length of the String Provided.
private bool IsPalindrome(string str)
bool flag = true;
for (int i = 0, j = str.Length - 1; i < str.Length / 2; i++, j--)
if (str[i] == str[j])
flag = false;
//If the string is not Palindrome it will return false else return true
return flag;

Comments or Responses

Login to post response