原方法可行,但发现网友方法更好。遂改之。
string appPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
自己又发现一个不错方法:
string appPath = System.IO.Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);
通过比较两种获取应用程序路径的方法,本文最终采用效率更高、更简洁的方案。第一种方法使用System.Reflection来获取执行程序的模块全名,而第二种方法直接利用Environment.GetCommandLineArgs获取参数目录。在实践过程中,后者在代码简洁性和性能上表现出优势。
原方法可行,但发现网友方法更好。遂改之。
string appPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
自己又发现一个不错方法:
string appPath = System.IO.Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);

被折叠的 条评论
为什么被折叠?