有谁知道如何为Func和Action指针声明源代码?我试图理解使用委托进行异步调用的理论以及与线程绑定的方式。Func <>和原始代码
例如,如果我有代码如下:
static void Main()
{
Func<string, int> method = Work;
IAsyncResult cookie = method.BeginInvoke ("test", null, null);
//
// ... here's where we can do other work in parallel...
//
int result = method.EndInvoke (cookie);
Console.WriteLine ("String length is: " + result);
}
static int Work (string s) { return s.Length; }
我将如何使用“委托”型替换函数功能<>结构;我想弄明白的原因是因为Func只能接受一个输入和一个返回变量。它不允许它指向的方法具有设计灵活性。
谢谢!
我将如何替换上面的代码中的这个实例化,以便我可以调用beginInvoke()方法并将其指向Work()方法? – locoboy 2010-11-05 10:43:18
看看我编辑过的文章。我可以在这里回答,因为我必须发布代码 – 2010-11-05 13:26:09
谢谢,这是我寻找的答案 – locoboy 2010-11-06 10:58:04