你的位置:首页 > ASP.net教程

[ASP.net教程]C#面向对象 类的封装


1 class student 2   { 3     public int _code; 4     public int Code//属性 5     { 6       //获取值 7       get 8       { 9         return 5;10       }11       //设置值12       set13       {14         _code = value + 9;15       }16     }17     private string _name;18     public string Name19     {20       get { return _name; }21       set { _name = value; }22     }  23   }24 25 student s = new student();26       s.Code = 3;27       Console.WriteLine(s.Code);28       Console.WriteLine(s._code);29       Console.ReadLine();