C# 类的规范写法

私有变量写在最上面,简单变量在上,复杂类型在下,以下划线_开头

类的常量紧随其后

不提供公共变量,所有变量以属性的方式对外开放

变量之后是属性

属性之后是方法,构造方法在最上方

公共方法随其后

最后是私有方法

例子:

 1     public class SimpleClass
 2     {
 3         private int _num;
 4         private string _word;
 5         private static readonly TimeZone _timeZone;
 6         private const double Pi;
 7         public DateTime Time{get;set;}
 8         public SimpleClass()
 9         {
10             //to do something
11         }
12         public SimpleClass(int num,string word)
13             :this()
14         {
15             //to do something
16         }
17 
18         public void OthePublicMethod()
19         {
20             //to do something
21         }
22 
23         private void OtherPrivateMethod()
24         {
25             //to do something
26         }
27     }
原文地址:https://www.cnblogs.com/yayaxxww/p/3820347.html