[200分求解]如何获得类名,在线等待 To:cnhgj(戏子)(黄某人养不成沙皮狗)Keyword 'this' is not valid in a static property, static method, or static field initializer 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼上的几位请注意这是一个静态属性,是不能用this的.不过还是感谢你们的回复. 这样就可以得到当前类的名字了,而不管你这个类是父类还是子类都能正确的返回当前的类的名字:public class ClassName { public static string aaa { get { return this.GetType().FullName; //这里怎么写? } } } 不要用静态方法public class ClassName { public string aaa { get { return this.ToString();; //这里怎么写? } } } http://community.csdn.net/Expert/topic/3525/3525002.xml?temp=.6565363思归的回答正解 就是啊,静态属性又不能继承,你可以在使用类的时候来判断或者用cnhgj(戏子)(黄某人养不成沙皮狗) 的代码 思归不都回答了吗public class ClassName { public static string aaa { get { return System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name; } } } 如果是静态函数的话则是MethodBase.GetCurrentMethod().ReflectedType.Name 但是思归的方法只能得到方法所在的类的名字,而不能得到由这个类继承得来的类的名字,所以我觉得还是做成一个非静态的方法,用:this.GetType().FullName来得到当前的类的名字. Excel一个很奇怪的问题 真的是十万火急呀!textBox.text内怎么判断文本中有一个某个字? C#当重新绘制主窗口如果用图片绘制 如何引路程序中? C# 进行DataTable结构数据操作的写法 请教一个关于缩略图的问题! 无法单步调试!5 写文件汉字乱码的问题 webbrowser控件刷新占资源 有没有在关闭窗口的同时也关闭别的窗口的方法 做一个c/s系统,规定可用的用户数为10个,当程序打开10个后,不让再登陆,该怎样做?? 我不小心把选项卡删了,杂个恢复哦! 请问有做过的吗:用c#实现给指定客户端发送消息,先查到ip,再用net send
不过还是感谢你们的回复.
public class ClassName
{
public static string aaa
{
get {
return this.GetType().FullName; //这里怎么写?
}
}
}
public class ClassName
{
public string aaa
{
get {
return this.ToString();; //这里怎么写?
}
}
}
思归的回答正解
public class ClassName
{
public static string aaa
{
get {
return System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name;
}
} }