public class student//创建一个学生类 { //数据成员列表 public string name; private uint age; protected char sex; internal string telephone; public string grade; //方法成员列表 public void say() { Console.WriteLine("Hello, 淄博汉企"); } public double Sum(double x, double y) { return x + y; } }
static void Main(string[] args) {//类的实例化 student stu=new student(); stu.name = "提莫"; stu.grade = "淄博汉企"; stu.telephone = "1234567"; //其他类型的成员此处不可用 Console.WriteLine(stu.name+stu.grade+stu.telephone); //方法调用 stu.say(); Console.Write(stu.Sum(2, 3)); Console.ReadLine(); }
时间: 2024-10-05 06:16:24