有下面一个类,和属性public class ClassName
{
public static string aaa
{
get {
return ""; //这里怎么写?
}
}
}我希望在程序中使用 ClassName.aaa可以得到 ClassName,当然ClassName是可变的.
{
public static string aaa
{
get {
return ""; //这里怎么写?
}
}
}我希望在程序中使用 ClassName.aaa可以得到 ClassName,当然ClassName是可变的.
Keyword 'this' is not valid in a static property, static method, or static field initializer
http://community.csdn.net/Expert/topic/3525/3525570.xml?temp=.9516565
不是一样的吗?这样就可以得到当前类的名字了,而不管你这个类是父类还是子类都能正确的返回当前的类的名字:
public class ClassName
{
public static string aaa
{
get {
return this.GetType().FullName; //这里怎么写?
}
}
}
public class ClassName
{
public string aaa
{
get {
return this.ToString();; //这里怎么写?
}
}
}
{
public static string aaa
{
get {
return System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name;
}
} }
{
public string aaa
{
get
{
return this.GetType().FullName; //这里怎么写
}
}
}
上领分.
this是对引用类的当前实例,而静态方法属于类本身,不能被实例化引用