有誰知道如何爲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