To:cnhgj(戏子)(黄某人养不成沙皮狗)
Keyword 'this' is not valid in a static property, static method, or static field initializer

解决方案 »

  1.   

    楼上的几位请注意这是一个静态属性,是不能用this的.
    不过还是感谢你们的回复.
      

  2.   

    这样就可以得到当前类的名字了,而不管你这个类是父类还是子类都能正确的返回当前的类的名字:
    public class ClassName
        {
            public static string aaa
            {
                get {
                    return this.GetType().FullName; //这里怎么写?
                }
            }
        }
      

  3.   

    不要用静态方法
    public class ClassName
        {
            public string aaa
            {
                get {
                    return this.ToString();; //这里怎么写?
                }
            }
        }
      

  4.   

    http://community.csdn.net/Expert/topic/3525/3525002.xml?temp=.6565363
    思归的回答正解
      

  5.   

    就是啊,静态属性又不能继承,你可以在使用类的时候来判断或者用cnhgj(戏子)(黄某人养不成沙皮狗) 的代码
      

  6.   

    思归不都回答了吗
    public class ClassName
        {
            public static string aaa
            {
                get {
                    return System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name;
                }
            }    }
      

  7.   

    如果是静态函数的话则是MethodBase.GetCurrentMethod().ReflectedType.Name
      

  8.   

    但是思归的方法只能得到方法所在的类的名字,而不能得到由这个类继承得来的类的名字,所以我觉得还是做成一个非静态的方法,用:this.GetType().FullName来得到当前的类的名字.