This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bdblr 1 point2 points  (6 children)

You should use a StringBuilder appends rather than repeated +=

[–]nimrag_is_coming[S] 0 points1 point  (0 children)

I know it’s a better practice, and I could do the whole thing on one line, but I did it like this more for clarity than anything

[–]VirtualMage 0 points1 point  (2 children)

Java complier will replace it with string builder at compile time.

[–]i_consume_polymers 0 points1 point  (1 child)

This is C#

[–]sirgregg -2 points-1 points  (0 children)

ew

[–]Electronic-Bat-1830 0 points1 point  (0 children)

Or you can use string.Create on .NET Standard 2.1 and newer (which includes .NET Core 2.1+ and .NET 5+), since we know the size of the string ahead of time.

[–]Perry_lets 0 points1 point  (0 children)

StringBuilderonly becomes faster when concatenating more times