Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stored strings, Locale resource files, using C# 6 Interpolation?

With the existing String.Format, I could throw the format string in a database or resource file, instead of having it hard coded into my application. Is that possible with Interpolation?

I'm guessing not, as it seems to be a compiler checked thing.

like image 546
JesusIsMyDriver.dll Avatar asked Aug 01 '15 22:08

JesusIsMyDriver.dll


1 Answers

No, it's a compiler thing as this:

string result = $"{name}";

Is compiled into this:

string result = string.Format("{0}", name);

And you can't run the compiler on these stored strings.

You can store the strings with the numbered parameters though, and use string.Format explicitly.

like image 143
i3arnon Avatar answered Oct 21 '22 18:10

i3arnon