c#3.0 coding habits and naming rules

Source: Internet
Author: User

1. Use Pascal casing rules to name methods, types, structs, interfaces, delegates, enumerations, enumeration items, properties, events, and so on.

public class DataGrid
{ 
          public void DataBind()
          {
          }
}

2. Name all variables, fields, and parameters with the Camel case rule.

Pascal can also be used camel case rules: constants, control IDs.

public class Product
{
          private string _productId;
          private string _productName;
          public void AddProduct(string productId,string productName)
          {
          }
}
public class BaseView:ViewPage
{
          protected Label label; //Camel命名控件ID
          protected Login Login1; //Pascal命名空间ID
}

3. All the private member variables are prefixed with "_".

public class DataBase
{
         private string _connectionString;
}

4. The name of the interface plus the prefix "I".

public interface IConvertible
{
         byte ToByte();
}

5. Custom attributes End With "attribute".

public class TableAttribute:Attribute
{
      //在使用这个属性时,不冲突的情况下,直接可以省掉 TableAttribute后面的Attribute用Table也可以。
}

6. Custom exceptions end with exception.

public class NullEmptyException:Exception
{

}

7. Name of the method. It is generally named the verb-object phrase. (parameter as an object, in the absence of confusion, can be omitted.) )

public class File
{
            public void CreateFile(string filePath)
            {
            }
            public void GetPath(string path)
            {
            }
            public void Delete(string fileName)
            {

            }
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.