How can global function exist in C#?

前端 未结 7 1565
暖寄归人
暖寄归人 2020-12-29 05:58

How can global function exist in C# when everything is defined inside a class? I was reading the documentation of OpCodes.Call at MSDN, and was surprised to see the followin

7条回答
  •  醉话见心
    2020-12-29 06:38

    I'm just overwriting my previous answer...

    Here is what each look like in IL DASM with their associated codes:

    // Static Method
    IL_0001:  call       void testapp.Form1::Test()
    
    // Instance Method
    IL_0001:  call       instance void testapp.Form1::Test()
    
    // Virtual Method
    IL_0001:  callvirt   instance void testapp.Form1::Test()
    
    // Global Function
    IL_0000:  call       void testapp.Test()
    

    So to answer your question, there isn't a direct way to generate the metadata token in the last method for C#. I had to create the last in C++.

提交回复
热议问题