什么是C#的命名约定? [英] What are the naming conventions in C#?

查看:120
本文介绍了什么是C#的命名约定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有在这几个问题,但他们似乎都针对语言的特定部分;

There are a few questions on this, but they all seemed to be targeting a specific part of the language;

  • What are the most common naming conventions in C#? - Asking specifically about getters/setters.
  • C# naming conventions - Asking more specifically about short uppercase suffixes.

我刚刚开始在C#与创业的朋友创造的Xbox Live Arcade游戏。我已经开发了一些使用ActionScript 2和第3场比赛,但要开始探索更强大的语言和设备。

I'm just starting out in C# with a friend on a venture to create games for XBOX Live Arcade. I've developed a number of games using ActionScript 2 and 3 but want to start exploring more powerful languages and devices.

我要确保我不忌讳,我开始工作(如果我得到这一点)的人,甚至只是人们对这里的时候,我遇到了麻烦,问一个问题的严重扰民/不正确的命名方法等。

I want to ensure that I don't peeve people that I start working with (if I get to that) or even just people on here when I run into trouble and ask a question with seriously disturbing / "incorrect" naming of methods, etc.

我发现它在例如code,我已经看到了,因为人们似乎从我目前的一些缺陷的观点混淆。我怀疑有缺陷的命名约定将使用,所以我意识到,我只是无法识别。

I've found it confusing in the example code that I've seen because there seems to be from my current point of view some flaws. I doubt that a flawed naming convention would be used, so I realize that I'm just having trouble understanding.

据我目前可以告诉,有这些约定:

As far as I can tell so far, there are these conventions:


  • public类型的someMethod()

  • 私有类型的someMethod() - ?没有下划线或任何

  • 公共静态类型的someMethod()

  • 私有静态类型_SomeMethod() - 这一次只是似乎很奇怪..

  • public类型someProperty - 它切换到驼色外套属性

  • 公共静态类型SomeProperty - 然后回到Pascal大小写静态..

  • public Type SomeMethod()
  • private Type SomeMethod() - no underscore or anything?
  • public static Type SomeMethod()
  • private static Type _SomeMethod() - this one just seems odd..
  • public Type someProperty - switching it up to camel casing for properties?
  • public static Type SomeProperty - and then going back to pascal casing for static..

在ActionScript 3中,我已经制定并严格坚持这些约定:

In ActionScript 3, I have developed and strictly stick to these conventions:


  • 私人变种_someVar

  • 公共变种someVar

  • 私有函数_someMethod()

  • 公共职能的someMethod()

  • 公共静止无功SomeStaticVar

  • 公共静态功能SomeStaticMethod()

  • 公共常量SOME_CONSTANT

  • private var _someVar
  • public var someVar
  • private function _someMethod()
  • public function someMethod()
  • public static var SomeStaticVar
  • public static function SomeStaticMethod()
  • public const SOME_CONSTANT

有没有命名,每个背后的原因约定,这样我可以让他们在我的头上的完整列表?语法(即 public类型方法()而不是AS3的公共函数法():类型)的逆转是抛我出足够的那个我知道我需要保持对我如何命名的东西眼睛的那一刻,否则我会忘记和养成不良习惯,这我宁愿钉,现在避免的。

Is there a complete list of naming conventions with reasoning behind each so that I can get my head around them? The reversal of syntax (i.e. public Type method() instead of AS3's public function method():Type) is throwing me out enough at the moment that I know I need to keep an eye on how I'm naming things, otherwise I'll forget and develop bad habits, which I'd rather nail and avoid now.

推荐答案

有是的所有多功能一体机code框架微软编码标准其中包含一套完整的规则和准则。 (也可用<一个href=\"https://1$c$c.$c$cplex.com/wikipage?title=All-In-One%20$c$c%20Framework%20Coding%20Standards\">here)

There is the All-In-One Code Framework Coding Standards from Microsoft which contains a complete set of rules and guidelines. (also available here)

本文档介绍了本地C ++和.NET(C#和VB.NET)的编码风格指南编程中使用了微软所有的多功能一体机code框架项目团队。

This document describes the coding style guideline for native C++ and .NET (C# and VB.NET) programming used by the Microsoft All-In-One Code Framework project team.

这篇关于什么是C#的命名约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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