What are the consequences, if any, of multiple backslashes in Windows paths?

后端 未结 1 1098
臣服心动
臣服心动 2021-01-20 03:13

In my programs I frequently have file names and/or paths that are configured in my app.config file. This will usually be something like:



        
相关标签:
1条回答
  • 2021-01-20 03:40

    There are no consequences that I know of, and it's not likely to be broken in future versions, because a lot of people will be doing the same as you.

    However, the correct way to combine paths in C# is to use Path.Combine, which will remove any extra backslashes for you:

    var logFile = Path.Combine(
        ConfigurationManager.AppSettings["LogFileDirectory"],
        ConfigurationManager.AppSettings["SaveLogFileTo"]);
    
    0 讨论(0)
提交回复
热议问题