1

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 of 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>
            ";
0

3 Answers 3

10

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>
        ";
Sign up to request clarification or add additional context in comments.

1 Comment

Oh wow, the @ works for multiple lines too! I thought it was only for the '\'. Anyway, thanks much, I learn something new all the time on Stack-O :)
2

Use literal strings:

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

Comments

2

Prefix the string with an "@"

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.