Another way,
public static class ReverseStringExtension
{
public static string Reverse(this string dataToRevese)
{
Func<string, string> reverseFunc = (dataToFunc) =>
{
StringBuilder reverseBuilder = new StringBuilder();
for (int index = 0; index < dataToFunc.Length; )
reverseBuilder.Append(dataToFunc[dataToFunc.Length - ++index]);
return reverseBuilder.ToString();
};
return string.IsNullOrEmpty(dataToRevese) ? default(string) : reverseFunc(dataToRevese);
}
}
Usage:
string stringRequireReverse = "Hello world, I am going to be reversed.";
stringRequireReverse = stringRequireReverse.Reverse();
Output:
.desrever eb ot gniog ma I ,dlrow olleH