首页 > 学院 > 开发设计 > 正文

C#面向对象类

2019-11-14 13:39:35
字体:
来源:转载
供稿:网友
 1 for (int i = 0; i < 10; i++) 2             { 3                 student.b++;//静态字段若不赋值,默认为1; 4                 new student().a++;//引用类型变量定义后,必须使用new关键字创建对象                                         才能后才能使用 5                 Console.WriteLine(student.b + " " + new student().a); 6             } 7             Console.WriteLine(new student().shu()); 8  9 
10 11 class student12     {13         public int a;14         public static int b;//静态成员不随着造对象初始化。类的静态方法只能访问                                    静态字段15         public int hanshu()16         {17             return a + b;//类的字段可以被实例方法直接调用18         }19         public int shu()20         {21           return  hanshu();//位于同一类中的普通方法可以相互调用22         }23                }

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表