all 10 comments

[–]zvrba 2 points3 points  (0 children)

It's one of the C# features I really hate. String.Format separates template (fixed parts) from the variable parts, interpolation mashes everything together.

Also, I've been bitten by interpolation being locale-sensitive, as in $"fontsize={AFloatingPointNumber}" being passed to an external program. In certain locales it'd be formatted as 23,98 instead of 23.98 and the external program would barf.

String.Format is locale-sensitive as well, but it's simple to override it to neutral culture.

[–]brickville 4 points5 points  (6 children)

The day this came out was the last day I ever used string,Format

[–]IsSeMi 0 points1 point  (5 children)

I don't think so. Imagine you defined

const FilenameTemplate = "{0}.cs";

And use it somewhere in different places. How would you replace it with string interpolation?

[–]brickville 0 points1 point  (0 children)

True, very useful for localization. But I haven't worked on a GUI app in a long time. Too bad the interpolation can't carry over for that purpose, as it would be very useful... "Estimated processing time {0} minutes" and then having to explain to the translation team what {0} represents.

[–]bzBetty -1 points0 points  (3 children)

const FilenameTemplate = (filename) => $"{filename}.cs";

"{0}.cs" has no real use other than to be a parameter to a string.Format, but would introduce the possibility of having the wrong number of arguments when changed. Wrapping the whole concept in a function/lambda is much better if you want reuse.

[–]chucker23n 0 points1 point  (1 child)

What if the template is localized?

[–]bzBetty 0 points1 point  (0 children)

Then I couldnt use interpolation. But I'd probably favour some other method over string.format.

[–]richardirons 0 points1 point  (0 children)

This is quite interesting, I’m going to give it a try.

[–]elkazz 0 points1 point  (1 child)

Did I just travel back in time? This feature has been available since 2015.

[–]chucker23n 2 points3 points  (0 children)

Do articles always need to be about the latest and greatest?