Home
Do you always make file paths @-quoted?
  v3.0 Posted at 10/20/2010 7:56 PM by System Account
In C#, backslashes in strings are special characters used to produce "escape sequences", for example \r\n creates a line break inside the string. This means that if you want to put a backslash in a string you must escape it out by inserting two backslashes for every one, e.g. to represent C:\Temp\MyFile.txt you would use C:\\Temp\\MyFile.txt. This makes the file paths hard to read, and you can't copy and paste them out of the application.

By inserting an @ character in front of the string, e.g. @"C:\Temp\MyFile.txt", you can turn off escape sequences, making it behave like VB.NET. File paths should always be stored like this in strings.

We have a program called SSW Code Auditor to check for this rule.

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address:

    Comments:

    Note: Social Media login for Yotpo is not working in IE or Safari, please use Chrome. We are waiting for Yotpo to fix it.