class Program { static void Main(string[] args) { ceshi wo; Student av = new Student(); wo=new ceshi(av.Sum); ceshi wo1=new ceshi(av.Avg); av.Age = 20; av.Shuxue = 100; av.Yingyu = 150; av.Yuwen = 120; Console.WriteLine("总成绩为{0}, 平均值为{1}", wo(av.Shuxue, av.Yuwen, av.Yingyu), wo1(av.Shuxue, av.Yuwen, av.Yingyu)); Console.ReadKey(); }
delegate double ceshi(double a, double b, double c); class Student { public double Sum(double a, double b, double c) { return a + b + c; } public double Avg(double a, double c, double b) { return (a + b + c) / 3; } private string name; private char sex; private int age; private double shuxue; private double yuwen; private double yingyu; public string Name { set {name = value;} get { return name; } } public int Age { set { age = value; } get { return age; } } public double Shuxue { set { shuxue = value; } get { return shuxue; } } public double Yingyu { set { yingyu = value; } get { return yingyu; } } public double Yuwen { set { yuwen = value; } get { return yuwen; } } }