今天看书时遇到了这样一个问题:<填写程序实现广播代理>,代码如下:
using System;
public delegate void MyDelegate(string input);
class A
{
public void delegateMethod1(string input)
{
Console.WriteLine("I come from Method1 and the input string is {0}",input);
}
public static void delegateMethod2(string input)
{
Console.WriteLine("I come from Method2 and the input string is {0}",input);
}
}
class B
{
public MyDelegate createDelegate()
{
A c2=new A();
MyDelegate sumD;
/***************************************
填写代码
***************************************/
return sumD;
}
}
class C
{
public void callDelegate(MyDelegate d,string input)
{
/***************************************
填写代码
***************************************/
}
}
class Driver
{
static void Main(string[] args)
{
B c2 = new B();
C c3 = new C();
MyDelegate d = c2.createDelegate();
/***************************************
填写代码
***************************************/
}
}
输出结果为:
I come from Method1 and the input string is share Message!
I come from Method2 and the input string is share Message!
中间的代码要这么写啊???为什么这么写啊?????能给我说说关于广播代理的相关知识吗?我一直搞不懂这个,还有什么委托之类的~~~
还有什么是异常处理程序啊?????
using System;
public delegate void MyDelegate(string input);
class A
{
public void delegateMethod1(string input)
{
Console.WriteLine("I come from Method1 and the input string is {0}",input);
}
public static void delegateMethod2(string input)
{
Console.WriteLine("I come from Method2 and the input string is {0}",input);
}
}
class B
{
public MyDelegate createDelegate()
{
A c2=new A();
MyDelegate sumD;
/***************************************
填写代码
***************************************/
return sumD;
}
}
class C
{
public void callDelegate(MyDelegate d,string input)
{
/***************************************
填写代码
***************************************/
}
}
class Driver
{
static void Main(string[] args)
{
B c2 = new B();
C c3 = new C();
MyDelegate d = c2.createDelegate();
/***************************************
填写代码
***************************************/
}
}
输出结果为:
I come from Method1 and the input string is share Message!
I come from Method2 and the input string is share Message!
中间的代码要这么写啊???为什么这么写啊?????能给我说说关于广播代理的相关知识吗?我一直搞不懂这个,还有什么委托之类的~~~
还有什么是异常处理程序啊?????
快帮帮我~~~~~~~