代码之家  ›  专栏  ›  技术社区  ›  Illep

C#字符串连接问题[已关闭]

c#
  •  -2
  • Illep  · 技术社区  · 4 年前

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

    var name = person.name; // Let's say the name is Alex.
    
    var htmlBody = " your name is <strong> {name } </strong> ";
    var htmlContent = $"{htmlBody}";
    

    我得到的结果是:

    你叫什么名字 {名称}

    相反,我想用等价于Alex的字符串替换{name}。我要怎么做?

    1 回复  |  直到 4 年前
        1
  •  5
  •   ema    4 年前

    分配时需要$ htmlBody 歪投球 htmlContent

    var name = person.name; // Let's say the name is Alex.
    
    var htmlBody = $" your name is <strong> {name} </strong> ";
    var htmlContent = htmlBody;