patterncsharpCritical
What's the @ in front of a string in C#?
Viewed 0 times
stringfrontwhatthe
Problem
This is a .NET question for C# (or possibly VB.NET), but I am trying to figure out what's the difference between the following declarations:
vs.
Printing out on the console doesn't make any difference; the length properties are the same.
string hello = "hello";vs.
string hello_alias = @"hello";Printing out on the console doesn't make any difference; the length properties are the same.
Solution
It marks the string as a verbatim string literal - anything in the string that would normally be interpreted as an escape sequence is ignored.
So
There is one exception: an escape sequence is needed for the double quote. To escape a double quote, you need to put two double quotes in a row. For instance,
So
"C:\\Users\\Rich" is the same as @"C:\Users\Rich"There is one exception: an escape sequence is needed for the double quote. To escape a double quote, you need to put two double quotes in a row. For instance,
@"""" evaluates to ".Context
Stack Overflow Q#556133, score: 997
Revisions (0)
No revisions yet.