C#定义一个类,并生成属性的例子

 1 class Person
 2     {
 3         private string name;
 4         private string age;
 5         private string job;
 6 
 7         public Person(string name,string age,string job)
 8         {
 9             this.name = name;
10             this.age = age;
11             this.job = job;
12         }
13 
14         //因为有get方法,所以必须要有返回类型
15         public string Name
16         {
17             get { return this.name; }
18             set { this.name = value; }//赋值的来源是系统级别的value变量,系统维护的
19         }
20 
21         public string Age
22         {
23             get { return this.age; }
24             set { this.age = value; }
25         }
26 
27         public string Job
28         {
29             get { return this.job; }
30             set { this.job = value; }
31         }
32     }
View Code

 

posted @ 2015-01-22 16:15  一菲聪天  阅读(479)  评论(0编辑  收藏  举报