-4

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
  • 13,730
  • 22
  • 106
  • 224

3 Answers3

22

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
  • 148,824
  • 21
  • 237
  • 306
1

You have to use the backslash like this:

var s = $"my name is \"{model.Name}\"";
Olli
  • 608
  • 5
  • 20
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
  • 148,824
  • 21
  • 237
  • 306