我正在尝试使用反射提取项目名称,但在子字符串方法中它给我“索引超出范围错误”。
string s = System.Reflection.Assembly.GetExecutingAssembly().Location;
int idx = s.LastIndexOf(@"\");
s = s.Substring(idx, s.Length);
我不明白为什么它在第三行给出错误。
请帮助。
最佳答案
尝试:
System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location)
关于c# - 使用反射获取执行程序集名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4848753/