Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8479185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:57:14+00:00 2026-06-10T18:57:14+00:00

I’m starting to learn C#, and I don’t understand why regular string literals (i.e.,

  • 0

I’m starting to learn C#, and I don’t understand why regular string literals (i.e., " ") cannot contain literal newline characters. (I’m not talking about the escape sequence \n). I know that you must use verbatim string literals (i.e., @" ") for multiline strings, but why?

regular string produces "Newline in constant" error verbatim string produces no error

I’ve not seen it explicitly stated that you cannot use them in regular strings. More than that, except where it’s mentioned in passing that I can use verbatim strings for this, everything I’ve read seems to suggest that literal newline characters would be allowed in regular string literals.

Beginning Visual C# 2010 and Code: Generating Multiline String Literals (Visual C#) show examples of verbatim multiline strings with no further explanation.

Learning C# 3.0 says this:

In the C# language, spaces, tabs, and newlines are considered to be whitespace…. Extra whitespace is generally ignored in C# statements. …
The exception to this rule is that whitespace within a string is treated as literal; it is not ignored.

So it’s literal? That’s what I would expect too, but it’s not.
It even includes this tip box:

Tip
Visual Basic programmers take note: in C#, the end-of-line has no special significance. Statements are ended with semicolons, not newline characters. There is no line continuation character because none is needed.

(I realize that this is talking about outside of strings, but why would end-of-line have special parsing significance inside a string if it doesn’t outside a string?)

Having finally found my way to the string (C# Reference) itself, I still garnered no insight:

String literals can contain any character literal. Escape sequences are included. The following example uses escape sequence \\ for backslash, \u0066 for the letter f, and \n for newline.

It says that escape sequences can be used, but it does not say they must be used. Are literal newline characters not included in “any character literal”? If I have a string that contains a literal tab character instead of its escape sequence \t, there is no error. But if I have a literal newline, I get an error. I’ve even changed the file’s line endings from \r\n to \n or \r to no effect.


Obviously, I’m able to infer from examples and from Visual Studio errors that a verbatim string is required if it contains a literal newline character, but everything I’ve read suggests that shouldn’t be the case. Why the difference?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:57:15+00:00Added an answer on June 10, 2026 at 6:57 pm

    Well, shoot. Right as I was submitting this, I found the answer.

    Are literal newline characters not included in “any character literal”?

    Apparently, no, they aren’t.

    2.4.4.4 Character literals:

    character-literal:

    ‘ character ‘

    character:

    single-character

    single-character:

    Any character except ‘ (U+0027), \ (U+005C), and new-line-character

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.