using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 事件
{
//声明委托
public delegate void GradedDelegate(int i,string n,double s);
public delegate void GradedDelegate2(int i, string n,double s, GradedDelegate s2);
class Student
{
//声明事件
public event GradedDelegate2 GradeEvent;
public string name;
public int ID;
public double score;
public void GetMessage(int id,string name,double score)
{
ID = id;
this.score = score;
this.name = name;
}
public void Notify()
{
if (GradeEvent != null)
{
Console.WriteLine("开始打分");
GradeEvent(ID, name, score,GetMessage);
}
}
}
class Teacher
{
public void SetScore(int i, string name, double s, GradedDelegate SetMessage)
{
Console.WriteLine("输入学生的学号");
Console.WriteLine("输入学生的姓名");
Console.WriteLine("输入学生的分数");
i=Convert.ToInt32(Console.ReadLine());
name = Convert.ToString(Console.ReadLine());
s = Convert.ToDouble(Console.ReadLine());
SetMessage(i, name, s);
}
}
class Program
{
static void Main(string[] args)
{
Student stu = new Student();
Teacher tea = new Teacher();
//注册事件
stu.GradeEvent+=new GradedDelegate2(tea.SetScore);
stu.Notify();
Console.WriteLine("学生的学号是:{0}/n学生的姓名为:{1}/n学生的成绩为:{2}", stu.ID, stu.name, stu.score);
Console.ReadLine();
}
}
}
///