获取使用反射执行的程序集名称反射、名称、程序

2023-09-03 01:05:58 作者:毙命

我想使用反射来拉项目名称,但子方法的过程中它给我索引超出边界错误。

I am trying to pull the project name using the reflection, but during the substring method it give me "index out of bound error".

string s = System.Reflection.Assembly.GetExecutingAssembly().Location;           
int idx = s.LastIndexOf(@"\");
s = s.Substring(idx, s.Length);

我不明白为什么它是在第三行给出错误。

I don't understand why it is giving error on the third line.

plz帮助。

推荐答案

尝试:

System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location)
 
精彩推荐
图片推荐