C#中获取当前路径的七种方法总结

分类:知识百科 日期: 点击:0

C#中获取当前路径的七种方法

在C#中,可以使用以下七种方法获取当前路径:

  • 1. 使用Environment.CurrentDirectory获取当前路径:
    string currentDirectory = Environment.CurrentDirectory;
  • 2. 使用Directory.GetCurrentDirectory获取当前路径:
    string currentDirectory = Directory.GetCurrentDirectory();
  • 3. 使用System.IO.Path.GetDirectoryName获取当前路径:
    string currentDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
  • 4. 使用AppDomain.CurrentDomain.BaseDirectory获取当前路径:
    string currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
  • 5. 使用System.AppContext.BaseDirectory获取当前路径:
    string currentDirectory = System.AppContext.BaseDirectory;
  • 6. 使用System.IO.Directory.GetParent获取当前路径:
    string currentDirectory = System.IO.Directory.GetParent(Environment.CurrentDirectory).FullName;
  • 7. 使用System.Reflection.Assembly.GetExecutingAssembly().Location获取当前路径:
    string currentDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
标签:

版权声明

1. 本站所有素材,仅限学习交流,仅展示部分内容,如需查看完整内容,请下载原文件。
2. 会员在本站下载的所有素材,只拥有使用权,著作权归原作者所有。
3. 所有素材,未经合法授权,请勿用于商业用途,会员不得以任何形式发布、传播、复制、转售该素材,否则一律封号处理。
4. 如果素材损害你的权益请联系客服QQ:77594475 处理。