C#面向对象 类

时间:2023-03-09 04:24:18
C#面向对象  类
  for (int i = ; i < ; i++)
{
student.b++;//静态字段若不赋值,默认为1;
new student().a++;//引用类型变量定义后,必须使用new关键字创建对象 才能后才能使用
Console.WriteLine(student.b + " " + new student().a);
}
Console.WriteLine(new student().shu());

C#面向对象  类


 class student
{
public int a;
public static int b;//静态成员不随着造对象初始化。类的静态方法只能访问 静态字段
public int hanshu()
{
return a + b;//类的字段可以被实例方法直接调用
}
public int shu()
{
return hanshu();//位于同一类中的普通方法可以相互调用
} }