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 sty ...

  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. cacti中监控squid的方法
  2. TypeError: __init__() got an unexpected keyword argument #34serialized_options #34
  3. Python基础教程: with语句详解
  4. [CODE FESTIVAL 2016]Distance Pairs
  5. Apache Spark概述
  6. Python基础语法学习整理
  7. 【古典入门】巴洛克音乐家-斯卡拉蒂
  8. 【跃迁之路】【722天】程序员高效学习方法论探索系列(实验阶段479-2019.2.12)...
  9. UE4之cmd调用函数
  10. 一道隐藏欺诈的JavaScript面试题
  11. 详解没有dSYM文件 如何解析iOS崩溃日志
  12. 哪种修复redis未授权访问漏洞的方法是相对不安全的_redis漏洞复现
  13. Delphi7调用dll(图文教程)2021最新
  14. 0.Java介绍(Java语言特点,什么是JDK、JRE、JVM,Java开发注意事项和细节说明,Java转义字符)
  15. 微信公众号 开发详解05【二维码制作、调查表单、短网址、微小宝、引流】
  16. windows当服务器不稳定,Win10上网不稳定经常掉线该如何解决?方法分享
  17. mysql stmt attr set_mysqli_stmt::attr_set()
  18. python小程序源码合集
  19. 4.8 HD-GR GNSS导航软件源码
  20. histogram loss笔记

热门文章

  1. 实现app直播源代码开发,完成短视频切换功能
  2. Date Structure: Graph --- Represent graph structure with adjacency list
  3. 如何在电脑重启后还能直接进行远程桌面
  4. Ultra96-V2入门使用(裸机)
  5. 尔雅科学计算与matlab,科学计算与MATLAB语言尔雅2020年章节答案
  6. HTTP权威指南(国内首本HTTP及其相关核心Web技术权威著作)
  7. 中国大学MOOC测验爬取(上)
  8. 2021河南高考成绩查询倒计时,2021年高考倒计时时间
  9. 另辟蹊径,简单sojson分析
  10. vue拖拽组件插件 vue-draggable-resizable-gorkys