C#代码规范——成员分段
2013-04-23 09:07
260 查看
这里的基本整理一般原则是:
1. 尽可能少分段
2. 关于类的尽可能靠前(例如static),关于实际对象的尽可能靠后
3. 早生成的尽可能靠前
4. 公有的,接口的尽可能靠前
5. 抽象的,通用的,基础性的,被依赖靠前;继承过来的尽量靠前
6. 相对需要引起注意的尽量靠前
7. 其他一些以往经验考虑
// Order of execution
// 1. initialisation of fields with initialisers
// 2. static constructor
// 3. static member or object constructor
// 4. member invocation
// 5. destructor
// * nested types are instantiated when it's touched during any of the above steps and as per the same rule
1. 尽可能少分段
2. 关于类的尽可能靠前(例如static),关于实际对象的尽可能靠后
3. 早生成的尽可能靠前
4. 公有的,接口的尽可能靠前
5. 抽象的,通用的,基础性的,被依赖靠前;继承过来的尽量靠前
6. 相对需要引起注意的尽量靠前
7. 其他一些以往经验考虑
class Sample : BaseClass, IIntf1 { #region Enumerations enum EnumType { Const1, // ... } #endregion #region delegates public void SomeEventDelegate(EventArgs e); // ... #endregion #region Nested types public class PubNestedClass { // ... } private class PrivNestedClass { } #endregion #region Fields public static int InstanceCount = 0; public int IntValue = 30; private static int _count = 0; private int _privField; private const _constantField; private static _staticField; private SomeEventDelegate _eventHandlers; #endregion #region Constructors static Sample() // static constructor first if any { } public Sample(int a, int b) // constructor with the most comprehensive parameters { // ... } public Sample(int a) : this(a,0) { // ... } ~Sample() { } #endregion #region Properties #region IIntf1 members #region IIntf1.1 members // an interface that IIntf1 implements if any // ... #endregion public int Id { get; private set; } #endregion #region BaseClass members public new string BaseClassPropertyToOverwrite { ... } public override string BaseClassProperty { get {...} set {...} } #endregion public static int Count { get; private set; } public string Name { get; private set; } private int PrivProperty { get; set; } #endregion #region Methods // ... #endregion #region Events public event SomeEventDelegate { add { _eventHandlers += value; } remove { ... } } #endregion }
// Order of execution
// 1. initialisation of fields with initialisers
// 2. static constructor
// 3. static member or object constructor
// 4. member invocation
// 5. destructor
// * nested types are instantiated when it's touched during any of the above steps and as per the same rule
相关文章推荐
- C#代码规范——成员分段
- C#基础知识复习1代码规范-执行流程(c#)-面向对象-引用命名空间-封装-继承-访问修饰符-虚方法-静态成员-多态-抽象类等
- C#新手入门代码 LINQ 一个int型数组找到其中小于指定数的成员
- Unity3D C#代码注释规范及文档生成
- C#编写代码规范
- (3-1)Unity3D/项目:C#代码规范
- C#代码规范
- C# 代码注释规范
- 代码编写规范说明书(c#.net与asp.net)
- c#代码规范和质量检查
- 代码编写规范说明书(c#与asp.net)
- C#代码注释规范及文档生成
- C#与Java对比学习:类型判断、类与接口继承、代码规范与编码习惯、常量定义
- C#与Java对比学习:类型判断、类与接口继承、代码规范与编码习惯、常量定义
- C#代码规范 程序员必备的秘笈
- C#与Java对比学习:类型判断、类与接口继承、代码规范与编码习惯、常量定义
- c#基础精华01(强调代码规范,虚方法,抽象方法,接口)
- 代码规范之C#注释
- StyleCop(C#代码规范分析工具)---1.介绍,下载及配置
- C#访问同类实例的私有成员代码