Different ways to accomplish a task Part III in C# Programmers
SPONSORED LINKS
Recently in the C# forum there was a questions about reversing a string, the only catch is you cannot use any kind of a loop. So I thought this would be a cool way to see how many different ways we could come up with for accomplishing this (I know someone's going to use [il]Array.Sort()[/il] but that's ok). Let's try to be creative on this one.
I came up with a way using recursion:
CODE
public string ReverseStringUsingRecursion(string str, int len)
{
if (len == 1)
return str;
else
return ReverseStringUsingRecursion(str.Substring(len, str.Length – 1), -1) + str[0].ToString();
}
Let's see what you can come up with
See the rest here:
Different ways to accomplish a task Part III in C# Programmers