When Importing a DLL Why Do Methods Have To Be Declared Static and Extern?

c#

Solution

`static` - As they do not need instance of the class, those method's are call to system API and do not need any Initialization, can be used in static / non-static block

`extern` - The extern modifier is used to declare a method that is implemented externally. Since API methods are not declared in the class file itself, extern tell the compiler that method declared else-where.

Problem

As the title asks, when you import a DLL such as User32.dll and declare methods to call methods on that DLL why do the methods need to be declared as Static and Extern. I.E, this was taken from another StackOverflow answer, but demonstrates what I'm asking. ``` [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, UIntPtr dwExtraInfo); ```

Original source