What's the in front of a string in C?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
In C#, the @ before a string literal means “treat this as a verbatim string.” That changes how escape sequences work and makes certain strings, especially file paths, regular expressions, and multi-line text, much easier to read.
What @ Changes in a String Literal
A normal C# string interprets backslash sequences such as \n and \t. A verbatim string does not. Most characters are taken literally.
Compare these two strings:
Both produce the same output, but the verbatim version is easier to write because you do not need to double every backslash.
That is the core purpose of @ for strings. It reduces escaping noise.
Common Use Cases
The most common place you will see @ strings is file-system code:
It is also useful for regular expressions, where backslashes otherwise pile up quickly:
Without @, the pattern would need extra escaping and become harder to scan.
Another nice use case is multi-line text:
Because the string is verbatim, the line breaks are preserved directly in the source.
How to Include Quotes Inside a Verbatim String
The main escaping rule that remains is double quotes. In a verbatim string, you include a quote by writing it twice.
That often surprises people because backslashes stop being special, but quotes still need special handling.
Verbatim Strings and Interpolation
You can combine @ with string interpolation by writing $@"..." or @$"...". That gives you both features at once: literal backslashes and embedded expressions.
This is a very common pattern in real applications. You keep the readability of a verbatim path while still inserting variables.
How This Differs From Newer Raw String Literals
Modern C# also has raw string literals using triple quotes. Those are great for JSON, SQL, markup, and other text-heavy content.
That does not make @ obsolete. Verbatim strings are still concise for paths, regex patterns, and smaller multi-line literals. Raw strings are usually better when the content itself contains many quotes or formatting characters.
So if you see @"...", think “verbatim string.” If you see """...""", think “raw string literal.”
Practical Rule of Thumb
Choose a normal string when ordinary escaping is simple and short. Choose a verbatim string when backslashes or line breaks make the normal form harder to read. Choose a raw string literal when the text itself is large or quote-heavy.
That is a readability decision, not just a syntax trick. The best form is the one that makes the code easiest to understand later.
Common Pitfalls
The most common pitfall is assuming @ disables all special rules. It mainly changes backslash handling, but embedded double quotes still need to be doubled.
Another mistake is using @ on a string and then expecting \n to become a newline. In a verbatim string, \n stays as the two characters backslash and n.
A third issue is confusing @ on strings with @ on identifiers. In C#, @class is an escaped identifier, while @"text" is a verbatim string. They are related only by syntax, not by meaning.
Finally, developers sometimes keep giant verbatim strings where a raw string literal would now be much clearer. Use the most readable modern option available in your codebase.
Summary
- '
@before a C# string literal creates a verbatim string.' - Verbatim strings treat backslashes literally, which is helpful for file paths and regex patterns.
- Multi-line text can be written directly inside a verbatim string.
- To include a double quote inside a verbatim string, write it twice.
- Combine
@with$when you need both literal formatting and interpolation.
Related reading
- What's the meaning of UseTaskFriendlySynchronizationContext?
- What's the 'obj' directory for in .NET?
- What's the role of GetHashCode in the IEqualityComparerT in .NET?
- What''s the role of the ClaimsPrincipal, why does it have multiple Identities?
- What's the strangest corner case you've seen in C or .NET?
- What's the use of System.String.Copy in .NET?
- What's the use of the SyncRoot pattern?
- What's wrong with using Thread.Abort

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.