怎样得到实例变量的名称?
怎样得到实例变量的名称?
class Test {
public string GetInstanceVariableName() {
string name = "";
/*
* 怎样得到实例变量的名称?
* 如Test t = new Test()时,t.GetInstanceVariableName返回t
* 如Test t2 = new Test()时,t.GetInstanceVariableName返回t2
* 如Test test = new Test()时,t.GetInstanceVariableName返回test
*
*/
return name;
}
}
问题点数:100、回复次数:3Top
1 楼eyestrong(有时爱情图有虚名)回复于 2003-12-03 08:44:46 得分 50
使用反射。
相关信息请参照:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpguide/html/cpcondynamicallyloadingusingtypes.htmTop
2 楼realMAX(♂ 困惑的浪漫 ♀)回复于 2003-12-03 09:45:54 得分 1
upTop
3 楼brightheroes(在地狱中仰望天堂)回复于 2003-12-03 10:03:10 得分 49
想要达到什么效果?要利用这个变量名做什么?
see
http://expert.csdn.net/Expert/topic/2214/2214138.xml?temp=.3467676Top




