The backslash (""
) character is a special escape character used to indicate other special characters such as new lines (
), tabs (
), or quotation marks ("
).
If you want to include a backslash character itself, you need two backslashes or use the @
verbatim string:
var s = "\Tasks";
// or
var s = @"Tasks";
Read the MSDN documentation/C# Specification which discusses the characters that are escaped using the backslash character and the use of the verbatim string literal.
Generally speaking, most C# .NET developers tend to favour using the @
verbatim strings when building file/folder paths since it saves them from having to write double backslashes all the time and they can directly copy/paste the path, so I would suggest that you get in the habit of doing the same.
That all said, in this case, I would actually recommend you use the Path.Combine
utility method as in @lordkain's answer as then you don't need to worry about whether backslashes are already included in the paths and accidentally doubling-up the slashes or omitting them altogether when combining parts of paths.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…