Palindrome algorithm in C# I had an interview yesterday where I had to write an algorithm on the whiteboard for working out if a value is a Palindrome in C#. The pressure got to me a bit but I've written my version of it in Visual Studio this evening.

 private bool Ispalindrome(string args)
        {
            var index = 0;
            var reverseArray = args.ToCharArray();

            do
            {
                if(index == args.Length)
                    return true;

                index++;
                var startingChars = args.Substring(0, index);
                var stringbuilder = new StringBuilder();

                for (var i = 0; i &lt; index; i++)
                {
                    stringbuilder.Append(reverseArray[reverseArray.Length-i-1]);
                }

                if (startingChars != stringbuilder.ToString())
                    _isPalindrone = false;

            } while (_isPalindrone);
            return _isPalindrone;
        }


Doe anyone have any recommendations on how to make this more efficient?
You are making it harder than it needs to be.

You just need to compare one character at a time:

private static bool IsPalindrome(string s)
{
    if (string.IsNullOrEmpty(s))
        return false;
    char[] chars = s.ToLower().ToCharArray();
    for (int i = 0; i &lt; chars.Length / 2; i++)
        if (chars[i] != chars[chars.Length - 1 - i])
            return false;
    return true;
}


Or:

private static bool IsPalindrome(string s)
{
    if (string.IsNullOrEmpty(s))
        return false;
    char[] chars = s.ToLower().ToCharArray();
    for (int i = 0, j = chars.Length - 1 ; i &lt; j; i++, j--)
        if (chars[i] != chars[j])
            return false;
    return true;
}