-1

I have this:

var s = $"my name is {model.Name}":

and I want the string to be:

"my name is "someone""

How can I do this?

Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263

3 Answers3

24

Simply like you would do without string interpolation:

var s = $"my name is \"{model.Name}\"";

With the string verbatim it gets a little different:

var s = $@"my name is ""{model.Name}""";
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
1

You have to use the backslash like this:

var s = $"my name is \"{model.Name}\"";
Olli
  • 658
  • 5
  • 26
1

You can use double quote escape \":

var s = $"my name is \"{model.name}\"";

You can find here and here more character escape sequences available in .NET.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325