theraot / Theraot

Backporting .NET and more: LINQ expressions in .net 2.0 - nuget Theraot.Core available.
MIT License
158 stars 30 forks source link

Bug of StringHelper.Append(string, string[]) #172

Closed CreateAndInject closed 2 years ago

CreateAndInject commented 2 years ago

https://github.com/theraot/Theraot/blob/c67d4fb1aba7c1029a793964fee110a8b2e6801f/Framework.Core/Theraot/Core/StringHelper.cs#L22-L25

string result = "a".Append("b", "c", "d", "e"); // result: "aSystem.String[]"

NN--- commented 2 years ago

IMO the best solution is to remove this method as implementing it efficiently is not so easy. For instance string.Concat(IEnumerable) presents only since .NET 4.0 and using string.Concat(string[]) means allocating a new array and copying the older one. If you look in the string.Concat implementation it has various optimization techniques: https://source.dot.net/#System.Private.CoreLib/String.Manipulation.cs,193

The simplest way for now is to use StringBuilder.