日期:2014-05-17 浏览次数:21253 次
        private int _weight;
        public int Weight
        {
            get
            {
                return this._weight;
            }
            set
            {
                if (value <= 0)
                    Console.WriteLine("cow {0} is eating", this.Name);
                else
                    this._weight = value;
            }
        }
------解决方案--------------------
int 类型的变量需要初始化
------解决方案--------------------
初始化下int类型的属性 private int _weight=0; 
   if(this._weight  <=0) 
 { 
   Console .WriteLine ( "cow {0} is eating ", this.Name); 
 } 
 else 
 { 
   this._weight = value; 
 } 
------解决方案--------------------
同问啊,if(this.weight<=0)这里的weight用的是初始默认值而不是输入的值吗
------解决方案--------------------