which is faster

so in c# there is something called StringBuilder i just figured it days ago so my question which is is better to use string extra = "Hello " + " World " + " extra stuff"; or to use StringBuilder for same purpose when I searched in Google it says that stringbuilder is much faster so just wanted to ask and make sure.
5 Replies
Pobiega
Pobiega11mo ago
tldr: string builder is probably the fastest, especially for longer combinations. but for something trivial like var greeting = "Hello " + name + ", welcome to my program!"; then string interpolation is your best bet being var greeting = $"Hello {name}, welcome to my program!"; yeah, go for a builder
𝔄ℑ𝔇𝔈𝔑
𝔄ℑ𝔇𝔈𝔑OP11mo ago
thanks
canton7
canton711mo ago
These days, string interpolation is almost always going to be faster than a StringBuilder
Pobiega
Pobiega11mo ago
for shorter sequences, yes. for longer sequences it will use a stringbuilder (but perhaps better than you did) oh he deleted the screenshot. It was a ~30-40 different things being concatted to build some kind of package payload
canton7
canton711mo ago
Yep exactly, and it'll use StringBuilder in a way which doesn't require creating intermediate strings
Want results from more Discord servers?
Add your server