小编Lee*_*ury的帖子

使用C#6中的命名参数进行字符串插值

鉴于我有一个存储在我的数据库中的元数据资源字符串将返回如下:

var pageTitle = "Shop the latest {category1} Designer {category2} {category3} at www.abc.com";
Run Code Online (Sandbox Code Playgroud)

我想替换{placeholders}变量values;

var category1 = "womenswear";
var category2 = "dresses";
var category3 = "cocktail dresses";
Run Code Online (Sandbox Code Playgroud)

我试过了,没有运气;

var newTitle = $"pageTitle, category1, category2, category3";
var newTitle = $(pageTitle, category1, category2, category3);
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用string.Replace()它有性能开销.有谁知道如何使用最新的C#字符串插值有效地完成这项工作?

c# asp.net asp.net-mvc

18
推荐指数
4
解决办法
3597
查看次数

标签 统计

asp.net ×1

asp.net-mvc ×1

c# ×1