.NET框架-微软给出的C#编程风格代码实例

黄舟
Lepaskan: 2017-03-18 11:39:02
asal
1983 orang telah melayarinya



from ms official guideline:

1 We use Allman style braces, where each brace begins on a new line.

while (x == y){
    something();
    somethingelse();
}finalthing();
Salin selepas log masuk

2 We use four spaces of indentation (no tabs).

3 We use camelCase for internal and private fields and use readonly where possible. Prefix instance fields with , static fields with s_ and thread static fields with t_. When used on static fields, readonly should come after static (i.e. static readonly not readonly static).

4 We avoid this. unless absolutely necessary.

5 We always specify the visibility, even if it’s the default. Visibility should be the first modifier.

private string _foo //betterstring _foo  //bad
Salin selepas log masuk
public abstract //betterabstract public //bad
Salin selepas log masuk

6 Namespace imports should be specified at the top of the file, outside of namespace declarations and should be sorted alphabetically.

using System.IO;using System.Collections;

namespace CAXA.MES.UI.Performance.Board
{  public class LinkedList
  {


  }

}
Salin selepas log masuk

7 Avoid more than one empty line at any time. For example, do not have two blank lines between members of a type.

8 Avoid spurious free spaces.

if (someVar == 0)...,
Salin selepas log masuk

9 If a file happens to differ in style from these guidelines (e.g. private members are named m_member rather than _member), the existing style in that file takes precedence.

10 We only use var when it’s obvious what the variable type is.

var stream = new FileStream(...) //var is OKay
var stream = OpenStandardInput() // here var is not good
Salin selepas log masuk

11 We use language keywords instead of BCL types.

 int, string, float // good
 Int32, String, Single // bad
Salin selepas log masuk

12 We use PascalCasing to name all our constant local variables and fields. The only exception is for interop code where the constant value should exactly match the name and value of the code you are calling via interop.

private const int Age=100; //good
Salin selepas log masuk

13 We use nameof(…) instead of “…” whenever possible and relevant.

14 Fields should be specified at the top within type declarations.

15 When including non-ASCII characters in the source code use Unicode escape sequences (\uXXXX) instead of literal characters.

Atas ialah kandungan terperinci .NET框架-微软给出的C#编程风格代码实例. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!