谢谢各位,我的疑问是:
怎么给属性赋值?怎么在类内部使用已经改变值的私有变量,如果AdType实际可能如下 
public int AdType { get{return _adid>100?_adid:0;} set{_adtype = value;} }

解决方案 »

  1.   

    public int AdType { get{....}set{......}}
    你可以把这个当成这样public int GetAdType()
    {
    //...逻辑
    return ....
    }
    public void SetAdType(int value)
    {
    //...逻辑
    }
      

  2.   

    直接用啊:
    public class M_Ad 

        // Fields 
        private int _adid;     // Properties 
        // public int AdId { get; set; } // <--- 如果需要自定义功能,把这句删掉,用下面一句:
        public int AdType { get{return _adid>100?_adid:0;} set{_adtype = value;} }
      

  3.   

    自动属性只不过是为了方便使用标准功能:
    public int AdId { get; set; }
    // 基本上相当于:
    public int AdId { get{return _adid;}; set{_adid=value;}; }是标准功能的简略写法而已。你如果需要自定义功能,可以像以前一样定义属性,不是一定需要使用自动属性的。