Tuesday, March 27, 2007

Funtion to Find whether the String is Palindrome or Not

using System;

class test
{

private static void Main()
{

Console.WriteLine("Is 'ada' Palindrome : {0}",IsPalindrome("ada"));
Console.ReadLine();
}

public static bool IsPalindrome(String strParam)
{
int iLength,iHalfLength;
iLength = strParam.Length - 1;
iHalfLength = iLength/2;

for(int iIndex=0;iIndex<=iHalfLength;iIndex++)
{
if(strParam.Substring(iIndex,1)!=strParam.Substring(iLength - iIndex,1))
{
return false;
}
}
return true;
}
}



2 comments:

Anonymous said...

I think you need to test your work.

Kiran Kumar said...

Thanks for correcting me. Now you can check it out.