Best practice for building file paths in C#

后端 未结 2 1690
春和景丽
春和景丽 2021-01-07 16:27

I\'m working on a C# project where I must build paths to various files and folders. These are all under one root folder which I have specified in my Web.config file.

<
相关标签:
2条回答
  • 2021-01-07 17:04

    Use the Path class to build up your paths. It will do the right thing.

    Performs operations on String instances that contain file or directory path information. These operations are performed in a cross-platform manner.

    var full = Path.Combine(baseDir, dirFragment);
    
    0 讨论(0)
  • 2021-01-07 17:19

    Use Path.Combine to concatenate path tokens.

    If the path is a file to set/change the extension use Path.ChangeExtension.

    0 讨论(0)
提交回复
热议问题