C# 推荐:“静态公共”或“公共静态”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/239961/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 19:24:09  来源:igfitidea点击:

Which is recommended: "static public" or "public static"

c#

提问by Peter van der Heijden

If you have a class member that is staticand public. Would you write static publicor public static? I know they are the same. But is there some recommendation / best practice for writing this?

如果您的班级成员是staticpublic。你会写static public还是public static?我知道他们是一样的。但是是否有一些建议/最佳实践来编写这个?

采纳答案by Mark Heath

see this question

看到这个问题

If you download the Microsoft StyleCopVisual Studio addin, it can validate your source code against the rules Microsoft use. It likes the access modifier to come first.

如果您下载 Microsoft StyleCopVisual Studio 插件,它可以根据 Microsoft 使用的规则验证您的源代码。它喜欢访问修饰符排在第一位。

回答by Epaga

I personally would go with public static because it's more important that it's public than that it's static.

我个人会选择 public static,因为它的 public 比它是 static 更重要。

And check this: http://checkstyle.sourceforge.net/config_modifier.html

并检查这个:http: //checkstyle.sourceforge.net/config_modifier.html

As well as this: http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html(These two links are for Java, but the concept is the same)

以及这个:http: //java.sun.com/docs/books/jls/second_edition/html/classes.doc.html(这两个链接是针对Java的,但概念是一样的)

Short version: "public static" is recommended and is far more common.

简短版本:推荐使用“public static”,而且更为常见。

回答by Firas Assaad

"public static" is far more common, so you might want to go with that just to increase readability for programmers who never stumbled upon "static public".

“public static”更为常见,因此您可能希望使用它只是为了增加从未偶然发现“static public”的程序员的可读性。

回答by Stewart Johnson

When nothing else matters, go with consistency. In this case the rest of the world uses public static, so I'd go with that too just to avoid unnecessary surprise in those reading your code.

当其他一切都不重要时,请保持一致。在这种情况下,世界其他地方都使用public static,所以我也会这样做,以避免在阅读您的代码的人中出现不必要的惊喜。