I'm trying to write a function to check whether a string is a palindrome, and using this example, I'm trying to reverse the string using a recursive anonymous function:
static Boolean checkPalindromeAnonRec(string str)
{
str = str.ToLower().Replace(" ", String.Empty);
Func<string, string> revStr = null;
revStr = delegate(string s)
{
if (s.Length > 1)
{ return revStr(s) + s[0]; }
else
{ return s; }
};
return (str == revStr(str));
}
But every time I run it I get a StackOverflowException
. It's not obvious to me why, any ideas?