命名约定控件 [英] Naming conventions for controls

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

问题描述

虽然在默认情况下VS工作编辑器生成的:

While working with VS by default the editor generates this:

<asp:Button ID="Button1" runat="server" Text="Button" />

现在生成的ID为Button1的即第一个字母大写。我的问题是什么是命名控制的最佳方式?

Now the ID generated is Button1 i.e First letter capital. My questions is what is the best way to name the controls ?


  • 提交按钮

  • SubmitButton

btnSubmit按钮

btnSubmit

或其他什么东西?

哪个命名约定被认为是好的?

Which naming convention is considered good ?

推荐答案

btnSubmit按钮是匈牙利命名法,我不个人认为很好的用户界面编程,因为控制类型是通过其在Visual Studio中声明或智能感知直接明显。

btnSubmit is Hungarian notation which I don't personally consider good for UI programming since the type of control is evident directly through its declaration or intellisense in Visual Studio.

提交按钮更好。通常它需要一个形式 - 目的-TypeOfControl

SubmitButton is better. Generally it takes a form - Purpose-TypeOfControl

例如

InputLabel
FirstNameLabel
LastNameLabel
CancelButton

这是一个很好的参考:
<一href=\"http://10rem.net/articles/net-naming-conventions-and-programming-standards---best-practices\">http://10rem.net/articles/net-naming-conventions-and-programming-standards---best-practices

更新:匈牙利符号也被了StyleCop / FxCop的劝阻。因此,它最好不要完全使用。

Update: Hungarian notation is also discouraged by stylecop/Fxcop. So its better to not to use entirely.

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

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