0

There is @ operator that you place infornt of the string to allow special characters in string and there is \. Well I am aware that with @ you can use reserved names for variables, but I am curious just about difference using these two operators with string.

Search on the web indicated that these two are the same but I still believe there has to be something different between @ and \.

Code to test:

string _string0 = @"Just a ""qoute""";
string _string1 = "Just a \"qoute\"";
Console.WriteLine("{0} | {1}",_string0, _string1);

Question: what is the difference between @"Just a ""qoute"""; and "Just a \"qoute\""; only regarding strings?

Edit: Question is already answered here.

Community
  • 1
  • 1
Karolis Kajenas
  • 1,523
  • 1
  • 15
  • 23
  • 2
    http://stackoverflow.com/questions/3311988/what-is-the-difference-between-a-regular-string-and-a-verbatim-string – Dmitry Bychenko Nov 10 '15 at 07:12
  • 1
    So basically no difference in substance, only in representation in the source. Once compiled they are identical. – Corey Nov 10 '15 at 07:33

2 Answers2

2

Using @ (which denotes a verbatim string literal) you can put any character into the string, even line breaks. The only character you need to escape is the double quote. The usual \* escape sequences and Unicode escape sequences are not processed in such string literals.
Without @ (in a regular string literal), you need to escape every special character, such as line breaks.

You can read more about it at the C# Programming Guide:
https://msdn.microsoft.com/en-us/library/ms228362.aspx#Anchor_3

Botz3000
  • 39,020
  • 8
  • 103
  • 127
1

@ is a verbatim string, it allows you not to escape every special character at a time, but all of them in the string.While \ just allows you to escape one certain character. More info about strings: https://msdn.microsoft.com/en-us/library/aa691090%28v=vs.71%29.aspx

3615
  • 3,787
  • 3
  • 20
  • 35