I'm brand-new to C#. Among the samples I've seen is the use of the @ symbol in front of quoted text. What's its purpose?

For my first program, I wrote one that opens Excel workbooks for retrieval and update. In the on-line samples I found, that symbol preceded the filename samples. I omitted that symbol, though, and my program works fine - which leaves me wondering why I see samples with that symbol in them.

Recommended Answers

All 5 Replies

It means that the string is "Literal". So you can't use escape strings in it.

For example:
Console.WriteLine(@"This\nis a new line");
Output: This\nis a new line

Console.WriteLine("This\nis a new line");
is a new line

Read this Microsoft article which explains what the @ symbol is used for. Too bad C and C++ don't have that.

Aha! Thanks guys.

Too bad C and C++ doesn't have that.

Yeah, languages tend to evolve and improve. Did you also notice that the # sign in C# is in fact two + signs merged together?

Too bad C and C++ don't have that.

C++11 supports raw string literals that accomplish the same goal.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.