This is the string reversal method in C# that I was investigating:
string s = "This is the way it is.";
string result = string.Empty;
for(int i = s.Length-1; i <= 0; i--)
{
result = result + s[i];
}
return result;
Assuming that the strings can get very very long. Why is it beneficial to use Stringbuilder in this case over concatenating to result using s[i] as shown above?
Is it because both result and s[i] are immutable strings and therefore an object will get created each time both of them are looked up? Causing a lot of objects to be created and the need to garbage collect all those objects?
Thanks for your time in advance.