IDesign发布了C#编程规范,小鸡射手从Only4Gurus下载浏览后决心抽时间翻译一下,以更好地学习。

目录内容如下:

1  命名规则和风格 Naming Conventions and Style
     2  编码惯例 Coding Practices
     3  项目设置和结构 Project Settings and Structure
     4  Framework特别指导 Framework Specific Guidelines
        4.1  数据访问 Data Access
        4.2  ASP.NET和Web Service ASP.NET and Web Services
        4.3  序列化 Serialization
        4.4  多线程 Multithreading
        4.5  Remoting Remoting
        4.6  安全 Security
        4.7  服务组件 Enterprise Services
     5  资源 Resources

今天只翻译了命名规则部分,译文及原文对照如下,其中的tip是附加的,:-)

命名规则和风格 
Naming Conventions and Style

1.  类和方法名采用Pascal风格
    Use Pascal casing for type and method names
    public class SomeClass
    {
       public SomeMethod(){}
    }
2.  局部变量和方法参数采用camel风格
    Use camel casing for local variable names and method arguments
    int number;
    void MyMethod(int someNumber)
    {}
3.  接口名采用I作为前缀
    Prefix interface name with I 
    interface IMyInterface
    {..}
4.  私有成员变量采用m_作为前缀
    Prefix private member variables with m_
    public class SomeClass
    {
       private int m_Number;
    }
5.  自定义属性类名采用Attribute作为后缀
    Suffix custom attribute classes with Attribute. 
6.  自定义异常类名采用Exception作为后缀
    Suffix custom exception classes with Exception.
7.  采用动词-对象对命名方法,例如ShowDialog()
    Name methods using verb-object pair, such as ShowDialog()
8.  有返回值的方法应该取名表示其返回值,例如GetObjectState()
    Methods with return values should have a name describing the value returned, such as GetObjectState().
9.  采用描述性的变量名。
    Use descriptive variable names.
    a) 避免采用单字母的变量名,如i或t;而是采用index或temp。
       Avoid  single character variable names, such as i or  t. Use  index or temp instead. 
    b) 对public和protected成员避免采用用匈牙利命名法
       Avoid using Hungarian notation for public or protected members. 
    c) 不要采用缩写(例如将number缩写为num)。
       Do not abbreviate words (such as num instead of number).
10.  总是使用C#预定义的类型,而不是使用System命名空间中的别名。例如:采用object不用Object,采用string不用String,采用int不用Int32。
     Always use C# predefined types rather than the aliases in the  System namespace.
     For example: 
     object NOT Object
     string NOT String
     int    NOT Int32
11.  对于泛型,类型采用大写字母。当处理.NET类型Type时保留后缀Type。
     With generics,  use capital letters for types. Reserve suffixing Type when dealing with the .NET type Type.
     // 正确:
     //Correct:
     public class LinkedList
     // 避免使用:
     //Avoid: 
     public class LinkedList
12.  采用有意义的命名空间名,例如产品名称或公司名称。
     Use meaningful namespaces such as the product name or the company name.
13.  避免使用类的全称,而是采用using语句。
     Avoid fully qualified type names. Use the using statement instead. 
14.  避免在命名空间内使用using语句。
     Avoid putting a using statement inside a namespace.
15.  将所有framework命名空间名放在一起,后面放自定义或第三方的命名空间名。
     Group all framework namespaces together and put custom or third party namespaces underneath.
     using System;
     using System.Collections;
     using System.ComponentModel;
     using System.Data;
     using MyCompany;
     using MyControls;
16.  采用委托推断,不要显式实例化委托。
     Use delegate inference instead of explicit delegate instantiation 
     delegate void SomeDelegate();
     public void SomeMethod()
     {}
     SomeDelegate someDelegate = SomeMethod;
17.  严格遵守缩进格式。
     Maintain strict indentation.
     a) 缩进采用3个空格。
        Use 3 spaces for indentation.
     b) 不用采用tab或非标准的缩进,如1、2或4个空格。
        Do not use tabs or non-standard indentation like 1, 2 or 4 spaces. 
18.  注释缩进和其注释的代码在同一层次。
       Indent comment at the same level of indentation as the code you are documenting.
19.  所有注释要经过拼写检查。拼写错误的注释表明开发的草率。
      All comments should pass spell checking. Misspelled comments indicate sloppy development. 
20.  所有成员变量应该定义在前面,和属性或方法间空开一行。
      All member variables should be declared at the top, with one line separating them from the properties or methods. 
     public class MyClass
     {
        int m_Number;
        string m_Name;

public void SomeMethod1()
        {}
        public void SomeMethod2()
        {}
     }
21.  局部变量的定义尽可能靠近它的初次使用。
       Declare a local variable as close as possible to its first use.
22.  文件名应该体现其包含的类。
       A file name should reflect the class it contains.
23.  当使用partial类型且每部分分配一个文件时,以类型名加P和序数命名每个文件。
       When using partial types and allocating a part per file, name each file after the type suffixed with a P and an ordinal number:
     //In MyClassP1.cs
     public partial class MyClass
     {}
     //In MyClassP2.cs
     public partial class MyClass
     {}
24.  左大括号总是放在新行中。
       Always place an open curly brace ({) in a new line.
25.  匿名方法模仿普通方法的布局,和匿名委托定义放在一行。
       With anonymous methods mimic the code layout of a regular method, aligned with the anonymous delegate declaration. 
     a) 遵守将左大括号放在新行的规则。
         Comply with placing an open curly brace in a new line
     delegate void SomeDelegate(string someString);
     //正确
     //Correct: 
     public void InvokeMethod()
     {
        SomeDelegate someDelegate = delegate(string name)
                                    {
                                       MessageBox.Show(name);
                                    };
        someDelegate("Juval");
     }
     //避免采用:
     //Avoid
     public void InvokeMethod()
     {
        SomeDelegate someDelegate = delegate(string name){MessageBox.Show(name);};
        someDelegate("Juval");
     }
26.  没有参数的匿名方法使用空括号。
       Use empty parenthesis on parameter-less anonymous methods
     a) 仅当匿名方法可能被用于任何委托时省略括号。
         Omit the parenthesis only if the anonymous method could have been used on any delegate.
     delegate void SomeDelegate();
     //Correct 
     SomeDelegate someDelegate1 = delegate()
                                  {
                                     MessageBox.Show("Hello");
                                  };
     //Avoid 
     SomeDelegate someDelegate1 = delegate
                                  {
                                     MessageBox.Show("Hello");
                                  };

之三

IDesign C#编程规范(一)相关推荐

  1. IDesign C#编程规范(之四)

    续之三,本文是IDesign C#编程规范的第三章. 3   项目设置和项目结构     Project Settings and Project Structure 1.  总是以4级警告建立项目( ...

  2. IDesign C#编程规范

    IDesign发布了c#编程规范,小鸡射手从only4gurus下载浏览后决心抽时间翻译一下,以更好地学习. 目录内容如下: 1  命名规则和风格 naming conventions and sty ...

  3. IDesign C#编程规范(一)

    idesign发布了c#编程规范,小鸡射手从 only4gurus 下载浏览后决心抽时间翻译一下,以更好地学习. 目录内容如下: 1  命名规则和风格 naming conventions and s ...

  4. [导入]IDesign C#编程规范[转]

    [转自 http://blog.csdn.net/zlei12/]         IDesign发布了C#编程规范,小鸡射手从Only4Gurus下载浏览后决心抽时间翻译一下,以更好地学习. 目录内 ...

  5. IDesign C#编程规范(二)

    2  编码惯例    Coding Practices 1. 避免在一个文件中放多个类.     Avoid putting multiple classes in a single file.  2 ...

  6. IDesign C#编程规范[转]

    原文转自:http://www.cnblogs.com/ShiningRay/archive/2005/04/11/135263.html 命名规则和风格  1.  类和方法名采用Pascal风格  ...

  7. Windows客户端C/C++编程规范“建议”——前言

    前言 工作中接触了很多编程规范.其中最有意思的是,公司最近发布了一版C/C++编程规范,然后我看到该规范的最后一段时,有这么一句:"该规范不适用于Windows平台开发".看来这份 ...

  8. Python编程规范及性能优化

    为什么80%的码农都做不了架构师?>>>    Ptyhon编程规范 编码 所有的 Python 脚本文件都应在文件头标上 # -*- coding:utf-8 -*- .设置编辑器 ...

  9. 【ES6】ES6编程规范 编程风格

    [ES6]ES6编程规范 编程风格 一.定义变量的规范 二.字符串 三.对象 四.数组 五.函数 查看更多ES6教学文章: 参考文献 引言:这是ES6系列教学的最后一篇.我们讲解一下ES6编程的规范. ...

最新文章

  1. BZOJ2118墨墨的等式[数论 最短路建模]
  2. ios开发两个简单的错误提示和原因
  3. 标准C程序设计七---46
  4. [css] 解释下css3的flexbox(弹性盒布局模型),以及它应用场景有哪些?
  5. (Docker实战) 第5篇:Centos7 拉取和部署搭建 NEXUS私服
  6. SVN 与 CVS 在【版本管理】上的区别~
  7. 【算法设计与分析】11 递归树
  8. 2021年十佳返利优惠券平台排名如下
  9. Spring Boot学习笔记(二十一)Spring boot 数据校验 @Validated、@Valid用法详解
  10. Android 集成腾讯Bugly
  11. signature=506ccff074d130c2e8d4e3268d3b44f1,Secure proxy signature schemes from the Weil pairing
  12. 转 一个游戏程序员的学习资料
  13. Python基础篇(九)-- 正则表达式
  14. springboot的jsp应该放在哪_七、SpringBoot项目集成JSP以及项目不同启动方式及访问路径配置...
  15. Android 中英文切换的实现。
  16. 假如我来架构12306网站
  17. Vue-cli 微博注册登录系统
  18. Android 交流分享汇总
  19. “爱心帮”APP走进厦门高校
  20. notepad++ 多行批量 标序号

热门文章

  1. 【读后感】Java Concurrency in Practice:7.线程池的使用
  2. ChatGPT已能模仿任何写作风格,让你的自媒体快速起号
  3. 检查json 或 yaml 文件格式
  4. 右键新建里面没有记事本和word以及excel简单解决
  5. 懒人有懒福,推荐个朗读软件
  6. 拓扑排序之java实现_有向图和拓扑排序Java实现
  7. 综合布线系统设计与实现
  8. 精灵盛典玛雅服务器账号,精灵盛典小号倒大号积分方法
  9. Ubuntu默认bashrc的存储位置
  10. 东软载波ESDS67-61模块调试心得