3 ms·
There's no reason in principle why name + " is " + age + " years old." couldn't compile to exactly the same. (Other than maybe `string.Format` having some
by layer8 2y ago
There's no reason in principle why
name + " is " + age + " years old."
couldn't compile to exactly the same. (Other than maybe `string.Format` having some additional customizable behavior, I don't know C# that well.)
- epcoa 2y agoLike python, and Rust with the format! macro (which doesn't even support arbitrary expressions), C# the full syntax for interpolated/formatted strings is this: {<interpolationExpression>[,<alignment>][:<formatString>]}, ie there is more going on then just a simple wrapper around concat or StringBuilder.
- ygra 2y agoWhen not using the format specifiers or alignment it will indeed compile to just string.Concat (which is also what the + operator for strings compiles to). Similar to C compilers choosing to call pits instead of printf if there is nothing to be formatted.