问题
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.
回答1:
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)}";
回答2:
You should put it as
private string sth = $"{String.Join("\\", Node.stringToType.Keys)}";
please, notice that the text within {...}
should be correct C# code
String.Join("\\", Node.stringToType.Keys)
As a further improvement, you don't want string interpolation at all:
private string sth = String.Join("\\", Node.stringToType.Keys);
来源:https://stackoverflow.com/questions/43077856/c-sharp-quotes-in-interpolated-string-unexpected-character-0022