How to use escape characters with string interpolation in C# 6?

后端 未结 7 543
孤街浪徒
孤街浪徒 2020-12-03 06:42

I\'ve been using string interpolation and loving it, however I have an issue where I am trying to include a backslash in my output, but am not able to get it to work.

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 06:58

    If I did not missunderstood. The solution is real simple

    var domain = "mydomain";
    var userName = "myUserName";
    var combo = $"{{{domain}}}\\{{{userName}}}";
    Console.WriteLine(combo);
    

    I share the birdamongmen answer as well good reference provided there. Hope it is helpfull to you. My 5 cents

提交回复
热议问题