Reputation: 16565
I want to ask why all extern method calls are static? How the CLR handles these calls?
Upvotes: 5
Views: 513
Reputation: 10875
extern
calls also must generally conform to a "C-style" API, and C doesn't know anything about objects, thus the calls are static
.
My statement isn't 100% true as there is a ThisCall calling convention which can be used with [DllImport] as an aid in calling C++ methods.
Upvotes: 2
Reputation: 1064114
Extern method calls are to unmanaged code. As such, it doesn't make sense to be called on a (managed) object instance - the first (hidden) argument in an instance method is the instance reference, aka this
. Typically, extern
methods just involve simple types (primitives, string, etc) - not objects (except perhaps arrays - and even they are often resolved to IntPtr
first).
Upvotes: 4