+ 1

why "/" instead of "\"?

I was making a practice program and when I wrote: bool txt = File.Exists(C:\text.txt"); it says "unrecognized escape secuence" but when I write: bool txt = File.Exists(C:/text.txt) it does recognize it. is there a config problem with my PC?

23rd Sep 2016, 7:42 PM
Alvaro
4 Answers
+ 5
You're using escape-sequence feature (\ starts escape sequence; \n and \r mean new line symbol, \t means tab symbol and so on). In your case you can write: bool txt = File.Exists("C:\\text.txt") // escape sequence for \ symbol Or bool txt = File.Exists(@"C:\text.txt") // ignores escape sequences
23rd Sep 2016, 9:36 PM
Ivan G
Ivan G - avatar
+ 3
wow. thanks!!!
31st Jan 2017, 4:37 AM
Fred Smith
Fred Smith - avatar
+ 1
thans man!! I'll try it right now!
23rd Sep 2016, 9:42 PM
Alvaro
0
this helped me, thanks @Ivan G
30th Jan 2017, 9:16 PM
Johnny.Fonseca
Johnny.Fonseca - avatar