C#委托的问题,望高手帮我详细解答,感谢...

来源:百度知道 编辑:UC知道 时间:2024/07/04 22:48:30
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication8
{
delegate void D(int i);
class Program
{
static void Main()
{
V(new D(R));
}
public static void R(int t)
{
V(21);

}
public static void V(int i)
{
Console.WriteLine(i.ToString());
Console.ReadLine();
}

}
}
这个程序问题在哪里??我不太懂,能帮我详细解释下吗...感谢

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication8
{
delegate void D(int i);//委托的定义
class Program
{
static void Main()
{
D x=new D(R);//x为委托D的实例(对象),R为x要调用的方法,也就说x委托R来实现
x(10);//触发x,也就是调用函数R
}
public static void R(int t)
{
V(t);

}
public static void V(int i)
{
Console.WriteLine(i.ToString());
Console.ReadLine();
}

}
}
//结果是10

我也不懂,貌似都没办法运行

给被委托的方法加一个delegate 就可以了,比如:
public delegate void

我不明白为什么要用委托来实现这个功能呢?