Does the order of external and static matter?

Comparing two files (old and new), I see:

private extern static void SipShowIM(uint dwFlag); 

... in the old file and:

 private static extern void SipShowIM(uint dwFlag); 

... in a new file.

Why they have changed, I do not know; Does it matter what comes first, external or static?

UPDATE

Resharper had to do this because I know I did not do this (directly), but here is another difference between the old ones:

 public volatile static bool ProcessCommands = true; 

... and new:

 public static volatile bool ProcessCommands = true; 
+4
source share
4 answers

No, the order of these keywords does not matter.

+2
source

Well, I do not believe that there is a difference between these two uses. I am just looking at MSDN code, I tried both paths ( extern static and static extern ) and both codes generate the same IL code.

 .method public hidebysig static int32 Main(string[] args) cil managed { .entrypoint // Code size 41 (0x29) .maxstack 4 .locals init ([0] string myString, [1] int32 CS$1$0000) IL_0000: nop IL_0001: ldstr "Enter your message: " IL_0006: call void [mscorlib]System.Console::Write(string) IL_000b: nop IL_000c: call string [mscorlib]System.Console::ReadLine() IL_0011: stloc.0 IL_0012: ldc.i4.0 IL_0013: call native int [mscorlib]System.IntPtr::op_Explicit(int32) IL_0018: ldloc.0 IL_0019: ldstr "My Message Box" IL_001e: ldc.i4.0 IL_001f: call int32 ProgramConsole.Program::MessageBox(native int, string, string, int32) IL_0024: stloc.1 IL_0025: br.s IL_0027 IL_0027: ldloc.1 IL_0028: ret } // end of method Program::Main 

So my money is NO .

+2
source

No, according to the C # specification, all ordinal modifications of the method are equivalent. Version 4.0, section B.2.7, page 493:

modifier method:
Modifier method
method-modifier

Modifier method:
new
the public
protected
interior
private
static
virtual
sealed
override
abstract
extern

This is clearly not a static constructor, but on page 497 (section B.2.7), both orders explicitly call:

static constructor modifiers:
extern opt static
static extern opt

+2
source

The order of the method modifiers does not matter. However, it is usually written as static extern .

Tools like StyleCop complain about this: SA1206: The 'static' keyword must come before the 'other' keyword in the element declaration. This is just a coding style issue.

+1
source

All Articles