C# 笔记 获取程序当前目录

在C#中,我们有以下几种方式获取程序当前目录:

            Console.WriteLine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
            Console.WriteLine(System.AppDomain.CurrentDomain.BaseDirectory);
            Console.WriteLine(System.Environment.CurrentDirectory);
            Console.WriteLine(System.IO.Directory.GetCurrentDirectory());
            Console.WriteLine(Environment.CurrentDirectory);

输出:

D:\MyTool\MyWorkRelated\C#_Tool\Defect Process Tool\DefectExcelProcesTool\DefectExcelProcesTool\bin\Debug
D:\MyTool\MyWorkRelated\C#_Tool\Defect Process Tool\DefectExcelProcesTool\DefectExcelProcesTool\bin\Debug\
D:\MyTool\MyWorkRelated\C#_Tool\Defect Process Tool\DefectExcelProcesTool\DefectExcelProcesTool\bin\Debug
D:\MyTool\MyWorkRelated\C#_Tool\Defect Process Tool\DefectExcelProcesTool\DefectExcelProcesTool\bin\Debug
D:\MyTool\MyWorkRelated\C#_Tool\Defect Process Tool\DefectExcelProcesTool\DefectExcelProcesTool\bin\Debug

亲测可以代码正确。

上一篇:蒙版


下一篇:位运算学习(一)--加 “两道只出现一次的数字”的习题