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 的等效字符串。我怎样才能做到这一点?
回答
您需要 $ 而分配htmlBody
not inhtmlContent
为时已晚:
var name = person.name; // Let's say the name is Alex.
var htmlBody = $" your name is <strong> {name} </strong> ";
var htmlContent = htmlBody;