C#中函数修饰符的顺序 [英] Order of function modifiers in C#

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

问题描述

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

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()
{}

这两个都很好,但是

当我编码时:

public void static Method()
{}

我收到以下错误:

成员修饰符 'static' 必须在前面成员类型和名称

Member modifier 'static' must precede the member type and name

方法必须有返回类型

推荐答案

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

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.

我不认为有任何标准顺序,人们随心所欲……我个人更喜欢放置访问修饰符(publicprivate、等),然后是 static 修饰符(如果有),然后是 virtualabstractoverride 修饰符(如果适用).

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).

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

See the C# spec for details (§10.6)

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆