Multiline String Concatenation with interpolation
Hi folks. I'm looking for some confirmation of my understanding of how the compiler deals with string concatenations.
I understand that if I break up a long literal string over a few lines for readability, the compiler will interpret that as a single string, and there will be no runtime overhead in doing this. So I can do:
var longString = "part 1 " +
"part 2"
Which is just as performant as:
var longString = "part 1 part 2" On a single line (imagine this is much longer, and hard to read on one line)
And not suffer from the performance impact of doing concatenations at runtime.
However, I'm not sure how this works with interpolated strings:
var interpolatedLongString = $"info: {xxx} " +
$"long text {yyy}"
Is the compiler smart enough to turn this into:
var interpolatedLongString = $"info: {xxx} long text {yyy}"
Thanks!
Andy
0 comments:
Post a Comment