10

I am hoping to use a "{" inside a string interpolation statement but I'm having trouble finding the escape character to do it.

var val = "ERROR_STATE";
var str = $"if(inErrorState){ send 1,\"{val}\" }"

Desired output:

if(inErrorState){send 1,"ERROR_STATE"}

The simple solution is to just not use string interpolation, but I think this way of doing it is easier to read.

Felix Castor
  • 1,475
  • 1
  • 16
  • 37

1 Answers1

27

Type { twice to escape it:

$"if(inErrorState){{send 1, \"{val}\" }}"

BTW you can do the same with double quotes.

Sergey Berezovskiy
  • 224,436
  • 37
  • 411
  • 441