0

In C# the following lines are 'substantively' equivalent:

string dir = @"c:\this\that\theother"

and

string dir = "c:\\this\\that\\theother"

According the documentation:

Note that in C#, because the backslash (\) is an escape character, literal backslashes in a string must be escaped or the entire string must be @-quoted.

My question is, is there any operational or functional advantage to either choice?

Cos Callis
  • 5,051
  • 3
  • 30
  • 57
  • 1
    I'm pretty sure there is no functional difference. Personally I prefer `@` myself. Much cleaner and easier to look at. https://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx = " In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a quote-escape-sequence" – sab669 Jul 17 '15 at 14:53
  • 2
    See [duplicate](http://stackoverflow.com/questions/14583874/verbatim-string-literals-v-escape-sequences), especially Marc's comment _"As for which to choose: whichever is more convenient"_. I hope you don't expect us to list all differences between the two notations. If you have a _specific_ question (_"Which notation is more convenient to use for path strings"_, or _"Which notation to use if I want to include `\n`"_), please edit your question to include that. – CodeCaster Jul 17 '15 at 14:56
  • 1
    I agree that this is a duplicate question...I only wish that when I did an SO search for "C# @ vs. Escape" it would have come up. (I checked and it does come up on a Google Search...) – Cos Callis Jul 17 '15 at 14:59
  • Yeah, SO's search doesn't ever work for me. No hard feelings! ;) – CodeCaster Jul 17 '15 at 14:59
  • 1
    I think duplicate questions have a place, if only to help users who found it find the other more obscure original. – leigero Jul 17 '15 at 15:04
  • So, since this is a duplicate question, should I delete it or leave it as path to the answer for others possibly trying the same search? – Cos Callis Jul 17 '15 at 15:07
  • 1
    I say leave it, if the community wants it closed they can close it, but typically duplicate questions, by default, are not closed. They remain so that other users who find it can easily find the original and get the help they need. – leigero Jul 17 '15 at 15:16

0 Answers0