C#6.0 string interpolation localization

前端 未结 9 1248
感情败类
感情败类 2020-11-29 04:59

C#6.0 have a string interpolation - a nice feature to format strings like:

 var name = \"John\";
 WriteLine($\"My name is {name}\");

The ex

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 05:34

    Interpolated strings can not refactored out from their (variable) scope because of using of the embedded variables in them.

    The only way to relocate the string literal part is passing the scope bound variables as parameter to an other location, and mark their position in the string with special placeholders. However this solution is already "invented" and out there:

    string.Format("literal with placeholers", parameters);

    or some of advanced library (interpolating runtime), but using the very same concept (passing parameters).

    Then you can refactor out the "literal with placeholers" to a resource.

提交回复
热议问题