开发者

Getting String Definitions To Accept Multiple Lines?

开发者 https://www.devze.com 2023-01-18 01:09 出处:网络
For some reason, the syntax highlighting below is working how I\'d like it to, but this is not how it interprets the code in Visual Studio.When I try to assign multiple lines to a string, it won\'t le

For some reason, the syntax highlighting below is working how I'd like it to, but this is not how it interprets the code in Visual Studio. When I try to assign multiple lines to a string, it won't let me. Is there a way i can make the following work without combining all o开发者_JAVA百科f my code into one line or using a += for each new line?

        string HtmlCode = "";
        HtmlCode =
            "
                <head>
                    <style>
                        *{margin: 0px;padding: 0px;font-family: Microsoft Sans Serif;font-size: 11px;}
                    </style>
                </head>
            ";


Use verbatim string by prefixing your string with @

string HtmlCode = "";
HtmlCode =
        @"
            <head>
                <style>
                    *{margin: 0px;padding: 0px;font-family: Microsoft Sans Serif;font-size: 11px;}
                </style>
            </head>
        ";


Use literal strings:

string HtmlCode = @"                
    <head>
        <style>
        *{margin: 0px;padding: 0px;font-family: Microsoft Sans Serif;font-size: 11px;}             
        </style>
    </head>";


Prefix the string with an "@"

    string HtmlCode = "";
    HtmlCode =
        @"
            <head>
                <style>
                    *{margin: 0px;padding: 0px;font-family: Microsoft Sans Serif;font-size: 11px;}
                </style>
            </head>
        ";
0

精彩评论

暂无评论...
验证码 换一张
取 消