获取使用反射执行的程序集名称 [英] Get executing assembly name using reflection

查看:128
本文介绍了获取使用反射执行的程序集名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

这篇关于获取使用反射执行的程序集名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆