本文介绍了函数修饰符的顺序在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一个标准来设置C#中的函数修饰符的顺序。即

  public static void Method()
{}

static public void Method )
{}

这两个都很好,但是



当我编码:

  public void static Method()
{}

我收到以下错误:


解决方案

方法声明必须始终遵循此模式:

  [modifiers] returnType methodName([parameters])

修饰符的顺序没有规则,但它们必须始终在返回类型之前。



我不认为有任何标准订单,人们只是按照他们的意愿...个人我喜欢把访问修饰符( public private 等),然后 static $ c> virtual 抽象覆盖 >

有关详细信息,请参阅C#规范(§10.6)


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

public static void Method()
{}

static public void Method()
{}

this both work well, BUT

when I code:

public void static Method()
{}

I receive the following error:

and

解决方案

Method declarations must always follow this pattern:

[modifiers] returnType methodName([parameters])

There is no rule regarding the order of modifiers, but they must always precede the return type.

I don't think there is any standard order, people just do as they please... Personally I prefer to put the access modifier (public, private, etc) first, then the static modifier (if any), then the virtual, abstract or override modifier (if applicable).

See the C# spec for details (§10.6)

这篇关于函数修饰符的顺序在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-12 14:01