Reputation: 3
Is there another way of assigning string path to variable aside from this:
strPath = @"C:\Myfile.txt";
thanks.
Upvotes: 0
Views: 1142
Reputation: 74899
You can use forward slashes and it'll work fine on Windows and no escaping needed.
strPath = "C:/Myfile.txt";
Upvotes: 2
Reputation: 11858
You can use Unicode Escape Sequences....
string strPath = "C:\u005CMyfile.txt";
Upvotes: 1
Reputation: 20049
Do you mean another way of escaping the backslashes?
The @ sign at the start means that the string is treated as a verbatim string literal, and simple escape sequences such as \n or \t are ignored.
If you don't put the @ at the start it is not verbatim, and escape sequences are parsed. If you want to ignore an individual escape sequence you can precede it with a single backslash and it will be ignored.
The reason you would use it in a path such as your example is so that you don't have to escape each individual backslash as you would if you didn't put the @ at the start:
strPath = "C:\\Myfile.txt";
Upvotes: 3