属性被赋值和构造函数谁先执行

答案是属性先被赋值。原因是为什么?

 

 public ActionResult Test()
        {
            Person p=new Person();

            return Json(5, JsonRequestBehavior.AllowGet);
        }

    public class Person
    {
        public string Id { get; set; }
        public int Name
        {
            get
            {
                return 200; 
            }
        }
        public Person()
        {   //调用构造函数时,Name的值已经是200了。
            
        }
    }

 

posted @ 2013-07-30 19:05  瓜王  阅读(599)  评论(0编辑  收藏  举报