How can global function exist in C#?

前端 未结 7 1559
暖寄归人
暖寄归人 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:51

    You can't have global functions in C#, it's just not part of the language. You have to use a static method on some class of your choosing to get similar functionality.

    However C# is not the only language that uses the CLR. One can write Managed C++, which can have global functions.

提交回复
热议问题