日期:2014-05-17  浏览次数:20520 次

C#创建类属性的小问题,求解答
打个比方,如下面两段代码: 
代码1:
public partial class Account
    {
        public int RoleType { get; set; }
    }
代码2:
public partial class Account
    {
        private int roletype;
        public int RoleType { 
          get{return roletype;}
          set{roletype=value;}
          }
    }

这两种写Modle属性的方式分别都是在什么情况下使用的?有什么区别?

------解决方案--------------------
上面一种是3.5的语法结构,很简洁,当然换成下面的写法也没问题;下一种是2.0或以下版本的写法,换成上面的写法就不行了。用法一样,没区别