C#字符串连接问题

c#

我在尝试连接字符串时遇到问题。代码如下:

var name = person.name; // Let's say the name is Alex.

var htmlBody = " your name is <strong> {name } </strong> ";
var htmlContent = $"{htmlBody}";

我得到的输出是:

你的名字是{name}

相反,我想将 {name} 替换为 Alex 的等效字符串。我怎样才能做到这一点?

回答

您需要 $ 而分配htmlBodynot inhtmlContent为时已晚:

var name = person.name; // Let's say the name is Alex.

var htmlBody = $" your name is <strong> {name} </strong> ";
var htmlContent = htmlBody;


以上是C#字符串连接问题的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>