string str = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
解码:Application.StartupPath 取程序启动路径
例如这样: “D:\C#XM\CeShi\CeShi\bin\Debug” 一开是取的是这样的东西
其实分开测试,就很容易懂的,一点就懂的,不妨可以自己断点试试看
分开测试:
int strCeShi = Application.StartupPath.LastIndexOf("\\");
string str = Application.StartupPath.Substring(0,strCeShi);
*上面的strCeShi 就是返回了\上一级结束的目录的长度
str的结果为: “D:\C#XM\CeShi\CeShi\bin”
从上面可以看 一开取的和str比较一下 就知道少了一级的目录,就是少了\Debug
然后后面也是这么操作直到取到程序的目录:D:\C#XM\CeShi\CeShi
多动手,自己断点,这个就会明白!!!*
196

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



