I would expect the code below (from the Exception class in .Net framework) to use a StringBuilder to build a string and then return a builder.ToString() instead of using the "+" operator on the existing string, which ends up creating a new string everytime.
I expect folks writing .Net source code to follow the best practices where ever possible, therefore I want to double check if this is still somehow optimal
private String ToString(bool needFileLineInfo, bool needMessage) {
String message = (needMessage ? Message : null);
String s;
if (message == null || message.Length <= 0) {
s = GetClassName();
}
else {
s = GetClassName() + ": " + message;
}
if (_innerException!=null) {
s = s + " ---> " + _innerException.ToString(needFileLineInfo, needMessage)
+ Environment.NewLine
+ " "
+ Environment.GetResourceString("Exception_EndOfInnerExceptionStack");
}
string stackTrace = GetStackTrace(needFileLineInfo);
if (stackTrace != null)
{
s += Environment.NewLine + stackTrace;
}
return s;
}