用C#写入"逐字字符串"

pro*_*eek 11 .net c# stringtemplate verbatim-string

我需要打印

a
"b"
c
Run Code Online (Sandbox Code Playgroud)

使用vebatim字符串,我在这里提出了关于多行代码模板的另一个问题.

我尝试使用逐字字符串如下:

using System;

class DoFile {

    static void Main(string[] args) {
        string templateString = @"
        {0}
        \\"{1}\\"
        {2}
        ";
        Console.WriteLine(templateString, "a", "b", "c");
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,我收到了这个错误.

t.cs(8,11): error CS1525: Unexpected symbol `{'
t.cs(9,0): error CS1010: Newline in constant
t.cs(10,0): error CS1010: Newline in constant
Run Code Online (Sandbox Code Playgroud)

\"{1}\" 不起作用.

怎么了?

man*_*lds 20

试试这个(""而不是"逃避")

string templateString = @"
        {0}
        ""{1}""
        {2}
        ";
Run Code Online (Sandbox Code Playgroud)

来自C#规范:http://msdn.microsoft.com/en-us/library/Aa691090

quote-escape-sequence:""


Sir*_*ver 8

在逐字字符串文字中,您使用""双引号字符.

string line = @"
{0}
""{1}""
{2}";
Run Code Online (Sandbox Code Playgroud)