Search code examples
c#c#-6.0string-interpolation

C# quotes in interpolated string Unexpected character \0022


I've read that you can use expressions in interpolated strings, but escaping quotes does not work.

private string sth = $"{String.Join(\"\", Node.stringToType.Keys)}";


Error CS1056: Unexpected character `\0022' (CS1056)
Error CS1525: Unexpected symbol `)', expecting `${', `:', or `}' (CS1525) 

UPDATE:

The inner expression above was ment to be equivalent to

String.Join("", Node.stringToType.Keys)

(the two backslashes were for escaping the two double quotes) like that you can insert there any delimiter.


Solution

  • Change it to this

    private string sth = $"{String.Join("\\", Node.stringToType.Keys)}";
    

    This way must work too

    private string sth = $"{String.Join(@"\", Node.stringToType.Keys)}";