zoukankan      html  css  js  c++  java
  • C# Coding Standard Naming Conventions and Style

     

    Naming Conventions and Style

    Use Pascal casing for type and method names and constants:

    User camel casing for local variable names and method arguments:

    void MyMethod(int someNumber)

    {

           int number;

    }

    Prefix interface names with I

    Interface IMyInterfance

    {

          

    }

     

    Prefix private member variables with m_. Use Pascal casing for the rest of a member variable name following the m_.

    public class SomeClass

    {

           private int m_Number;

    }

    Suffix customs attribute classes with Attribute.

    public class TagColumnAttribute : Attribute

    {

    }

    Suffix customs exception classes with Exception

    public class CEWorkstationException:Exception

    {

    }

     

    Name methods using web-object pair

    Such as: ShowExamTrackingDialog();

    Methods with return values should have a name describing the value returned.

    Such as: GetRequestedReportState()

    Use descriptive variable names.

    a)         Avoid single character variable names

    // void

    int i;

    int t;

    // instead

    int index;

    int temp;

    b)        Avoid using Hungarian notation for public or protected members

    c)         Do not abbreviate words

    // void

    int num;

    // instead

    int number;

    Always use C# predefined types rather than the aliases in the System namespace.

    Use

    Not Use

    object obj;

    Object obj;

    string strConnection;

    String strConnection;

    int index;

    Int32 index;

     

    With generics, use capital letters for types. Reserve suffixing Type when dealing with the .NET type Type.

    // Correct

    public class LinkedList<K,T>

    {

    }

    // Avoid

    public class LinkedList<KeyType,DataType>

    {

          

    }

    Use meaningful namespace

    CEWorkstation.Resource

    Avoid fully qualified type names. Use the using statement instead.

    using CEWorkstation.Resource

    Avoid putting a using statement inside a namespace.

    namespace CEWorksation.Resource

    {

           using System;

           using System.Data;

           using System.Web;

    }

  • 相关阅读:
    浏览器缓存学习
    文件上传
    compass与css sprite(雪碧图)
    记录一下删除过长目录的方法
    JavaScript学习之 倒计时
    HTML/CSS学习之 三列布局,其中左侧和右侧的部分宽度固定,中间部分宽度随浏览器宽度的变化而自适应变化
    JavaScript学习之setTimeout
    JavaScript实现,控制一个文本框只能输入正整数,如输入不符合条件则文本框全部字体标红
    关于本地文件请求json文件
    CSS3+HTML5特效9
  • 原文地址:https://www.cnblogs.com/wmz/p/CodeStandard.html
Copyright © 2011-2022 走看看