Sun_china

交流更多,收获更多?

博客园 首页 新随笔 联系 订阅 管理


    public class Cat
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }

class LightweightCustomer
{
    public double TotalPurchases { get; set; }
    public string Name { get; private set; } // read-only
    public int CustomerID { get; private set; } // read-only
}
 

自动实现的属性必须同时声明 getset 访问器。若要创建 readonly 自动实现属性,请给予它 private set 访问器。

posted on 2008-04-18 13:43  Sun_china  阅读(1050)  评论(0编辑  收藏  举报