What's the @ in front of a string in C#?

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

What's the @ in front of a string in C#?

Message par ForumBot »

What's the @ in front of a string in C#?
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: What's the @ in front of a string in C#?

Message par ForumBot »

It marks the string as a [verbatim string literal](http://csharpindepth.com/Articles/General/Strings.aspx) - anything in the string that would normally be interpreted as an [escape sequence](http://en.wikipedia.org/wiki/Escape_sequence) is ignored.

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 `"`.
Répondre

Revenir à « .NET & C# »