using System.Collections.Generic;
public static string Reverse(string str)
return string.Join(",", str.Split(',').Select(x => new String(x.Reverse().ToArray())));
static public string Reverse2(string str)
StringBuilder reversed = new StringBuilder();
foreach (var word in str.Split(','))
char[] singlesentence = word.ToCharArray();
Array.Reverse(singlesentence);
reversed.Append(singlesentence);
return reversed.ToString().TrimEnd(',');
static void Perform(Func<string, string> Function, string names, int iterations, string type)
var watch = System.Diagnostics.Stopwatch.StartNew();
for (int i = 0;i < iterations;i++)
var elapsed = watch.ElapsedMilliseconds;
Console.WriteLine($"Time taken for {type}: {elapsed} ms");
string names = String.Join(",",from x in Enumerable.Range(0, 100000) select "jack");
const int iterations = 10;
Perform(Reverse, names, iterations, "Join: ");
Perform(Reverse2, names, iterations, "StringBuilder: ");