Code template implementation with C#

狂风中的少年 提交于 2019-12-05 19:57:40

you need to place an @ before the first quote

templateString = @"
        {0}
        {1}
        {2}
        ";

make it a verbatim-string-literal

In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a quote-escape-sequence. In particular, simple escape sequences and hexadecimal and Unicode escape sequences *are not processed* in verbatim string literals. A verbatim string literal may span multiple lines.

Andrey

Do this instead (ad @ before the string constant):

class DoFile {

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

U can put @ before the variable name to get multiline strings.

You need to put @ before the quotation marks for the string, this will make it a verbatim string literal and this will still use all of the whitespace you use.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!