The requirement to escape \
inside a string if it is not a verbatim string (one that starts with @
) is a C# feature. When you start your application from a console, you are outside of C#, and the console does not consider \
to be a special character, so C:\test> myapplication.exe "C:\temp\january"
will work.
Edit: My original post had "C:\temp\january\"
above; however, the Windows command line seems to also handle \
as an escape character - but only when in front of a "
, so that command would pass C:\temp\january"
to the application. Thanks to @zimdanen for pointing this out.
Please note that whatever you put between quotes in C# is a representation of a string; the actual string may be different - for instance, \\
represents a single \
. If you use other means to get strings into the program, such as the command line arguments or by reading from a file, the strings do not need to follow C#'s rules for string literals. The command line has different rules for representation, in which a \
represents itself.