No, the order of those keywords does not matter.
Does the order of extern and static matter?
-
04-04-2022 - |
문제
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 the new file.
Why they got changed I don't know; does it matter which comes first, the extern or the static?
UPDATE
Resharper must have done this, because I know I didn't do this (directly) but here's another difference between old:
public volatile static bool ProcessCommands = true;
...and new:
public static volatile bool ProcessCommands = true;
해결책
다른 팁
Well, I don't believe there is a difference between this two usage. I just consider the code of MSDN page, I tried the both way (extern static
and static extern
) and the both code 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 for NO.
No, according to the C# specification, all method modifier orderings are equivalent. Version 4.0, section B.2.7, page 493:
method-modifiers:
method-modifier
method-modifiers method-modifiermethod-modifier:
new
public
protected
internal
private
static
virtual
sealed
override
abstract
extern
This clearly isn't a static constructor, but on page 497 (still section B.2.7), both orders are explicitly called out:
static-constructor-modifiers:
externopt static
static externopt
The order of method modifiers doesn't matter. It is however usually written as static extern
.
Tools like StyleCop complain about that: SA1206: The 'static' keyword must come before the 'other' keyword in the element declaration.
It is just a matter of coding style.