委托可以用来做方法的抽象,实现代码的解耦功能,下面举例来说明;
public static void mian()
{
list<Student> Students = new list<Student>();
Students.add(new Student(){"LiMing",95});
Students.add(new Student(){"LiMing",80});
IsGood isGood = GetGood;
IsGoodOne(Students ,isGood );
Console.ReakKey();
}
public bool GetGood(Student student)
{
if(student.Grade>90)
{
return true;
}
return false;
}
delegate bool IsGood(Student student);l
public calss Student()
{
public String name {get;set;}
public double grade{get;set;}
}
Public static calss IsGoodOne()
{
public void IsGoodStudent(list<Student> student,IsGood isGood)
{
foreach(var item in student)
{
if(isGood(item))
{
Concle.Write($"{item.name}is good");
}
}
}
}