在C#命名约定 [英] Naming Convention in c#

查看:140
本文介绍了在C#命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是C#中普遍接受的命名约定?
(函数,类,参数,局部变量,命名空间等)

What is the universally accepted naming convention for c#? (functions, classes, parameters, local variables, namespaces, etc)

推荐答案

微软拥有出色的一套准则在类库设计,包括命名一个部分。简而言之:

Microsoft has an excellent set of guidelines on class library design, including a section on naming. In short:


  • 类/结构体:PascalCase(WebRequest的)

  • 接口:PascalCase与我preFIX(IDisposable接口)

  • 方法:PascalCase(ToUpper的)

  • 命名空间:PascalCase(System.Collections中;不寻常的一个部分两个词虽然)

  • 非恒定的变量,包括参数:驼峰格式

  • 常量:PascalCase(Int32.MaxValue)

  • 枚举:PascalCase,奇异非标志和复数的标志(的HTTPStatus code,的BindingFlags)

  • 属性:PascalCase用属性后缀(ThreadStaticAttribute)

专用名称由你决定,但我倾向于遵循相同的约定作为一切。匈牙利命名法(在Win32中的样式)气馁,虽然很多地方用M_或_作为preFIX实例变量。

Private names are up to you, but I tend to follow the same conventions as for everything else. Hungarian notation (in the style of Win32) is discouraged, although many places use "m_" or "_" as a prefix for instance variables.

这篇关于在C#命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆