Function Modifier Order in C #

I would like to know if there is a standard for setting the order of function modifiers in C #. i.e.

public static void Method()
{}

static public void Method()
{}

it works well, BUT

when i code:

public void static Method()
{}

I get the following error:

The 'static' member modifier must be preceded by the type and name of the member

and

The method must have a return type

+3
source share
3 answers

Method declarations should always follow this pattern:

[modifiers] returnType methodName([parameters])

There are no rules regarding the order of modifiers, but they should always precede the return type.

, - , , ... (public, private ..), static ( ), virtual, abstract override ( ).

. # (§10.6)

+9

, void - . .

, , , .

(public ..) .

+4

.

#...

-:
:
- method-body

:
attributesopt method-modifiersopt partialopt return-type - type-parameter-listopt  ( -listopt) type-parameter-constraints-clausesopt

**** modifier method: ****
new
public
protected
internal
private
static
virtual
sealed
override
abstract
exbp
return type:
type
invalid
member name:
identifier
interface type. Identifier

+1
source

Source: https://habr.com/ru/post/1765590/


All Articles