Check if a string is palindrome or not without using string functions and without using loop instructions in C #

advertisements

Check whether a string is palindrome or not without using string functions and without using loop statements in C#. I can do without string functions but i don't know how to check without loop statements. I face this question in one of my interview.

using System;
namespace palindrome
{
    class Program
    {
        static void Main(string[] args)
        {
            string s,revs="";
            Console.WriteLine(" Enter string");
            s = Console.ReadLine();
            for (int i = s.Length-1; i >=0; i--) //**i want to replace this for loop**
            {
                revs += s[i].ToString();
            }
            if (revs == s) // Checking whether string is palindrome or not
            {
                Console.WriteLine("String is Palindrome \n Entered String Was {0} and reverse string is {1}", s, revs);
            }
            else
            {
                Console.WriteLine("String is not Palindrome \n Entered String Was {0} and reverse string is {1}", s, revs);
            }
            Console.ReadKey();
        }
    }
}


Willy-nilly you have to loop over the string; but you can hide the loop, make it implicit, e.g.

  bool result = Enumerable
    .Range(0, s.Length)
    .All(i => s[i] == s[s.Length - 1 - i]);

Sure this solution and alike are close to cheating