/*
* 烟台大学计算机学院学生
*All right reserved.
*文件名称:C#
*作者:孔云
*完成日期:2014年10月9日
*版本号:v1.0
*对任务及求解方法的描述部分:一次委托可以调用多个方法,称为委托多播或委托组合
*我的程序:
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
delegate void Delegt(int x,int y);//声明一个委托类型
public class MyClass
{
public void Sum(int a,int b)
{
Console.WriteLine(a+b);
}
public void Sub(int a,int b)
{
Console.WriteLine(a-b);
}
public void Sul(int a, int b)
{
Console.WriteLine(a*b);
}
public void Dce(int a, int b)
{
Console.WriteLine(b/a);
}
}
class Progtam
{
static void Main(string[] args)
{
MyClass c = new MyClass();
Delegt d = new Delegt(c.Sum);//创建委托对象
d += new Delegt(c.Sub);//一般通过+或-运算法实现多播的增加或减少
d += new Delegt(c.Sul);
d += new Delegt(c.Dce);
Console.WriteLine("输出结果为:");
d(6,9);
Console.WriteLine();
Console.ReadLine();
}
}
}
委托多播
最新推荐文章于 2022-05-07 08:32:09 发布