iT邦幫忙

1

c# Func泛型

小弟想問一下!
問甚麼c# Func的泛型中BeginInvoke不能用F12轉到定義查看

 Func<int, int, int> Sum = new Func<int, int, int>(
          (a, b) =>
          {
              return a + b;
          });
Sum.BeginInvoke(4, 5, MyAsyncCallback, Sum);

因為怎麼轉都是如下圖:
http://ithelp.ithome.com.tw/upload/images/20160814/20096630npsmKK37uy.jpg

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

4
fillano
iT邦超人 1 級 ‧ 2016-08-14 21:49:28
最佳解答

這就是你使用的Func定義,無法繼續下去是因為...

請先參考MSDN:System.Delegate 文中Remarks底下的第一個Note下的說明:

The common language runtime provides each delegate type with BeginInvoke and EndInvoke methods, to enable asynchronous invocation of the delegate.

簡單說,這是Common Language Runtime自動幫delegate加上的方法,沒有原始碼,所以你按下F12,最多就是看到Func的定義,底下沒有了...

你可以去.NET Core的原始碼裡面追追看:CoreCLR

  1. Func定義在:https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/Action.cs
  2. 有一個有趣的檔案:https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/Action.cs 看起來所有Base Class Libraries(簡寫BCL)的類別都會定義在這?
  3. 相關底層實作看起來在:https://github.com/dotnet/coreclr/tree/master/src/vm ,不過沒追下去了

以上...

石頭 iT邦高手 1 級 ‧ 2016-08-14 22:06:35 檢舉

所以程式會在CLR那邊在補上此方法的實作對吧?
學到學到^^謝謝大大的解說!

我要發表回答

立即登入回答