属性"ID"的正确命名约定是什么:ID或ID? [英] What's the proper naming convention for a property 'ID' : ID or Id?

查看:237
本文介绍了属性"ID"的正确命名约定是什么:ID或ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个非常简单的问题:当我有一个可持久对象时,它通常具有一个称为ID的属性(用于抽象类).

Pretty simple question: When i have a persistable object, it usually has a property called ID (for abstract classes).

那么..是命名约定ID还是ID?

So .. is the naming convention ID or Id?

例如

public int ID { get; set; }

public int Id { get; set; }

欢呼:)

PS.这是.NET btw的. FXCop整合将是一个奖励.

PS. This is for .NET btw. FXCop conformat would be a bonus.

推荐答案

我通常会使用标识符.如果我真的想使其简短(例如,作为较长标识符的一部分),则使用Id,除非它是参数或私有成员.

I usually go with Identifier. If I really want to keep it short (as part of a longer identifier, for example), I use Id, unless it's a parameter or private member.

.NET框架命名准则表示:

首字母缩写词是由术语或词组中的单词字母组成的单词.例如,HTML是超文本标记语言的缩写.仅当标识符广为人知且易于理解时,才应在标识符中包括首字母缩写词.首字母缩写词与缩写词的区别在于缩写词会缩短单个单词.例如,ID是标识符的缩写.通常,库名称不应使用缩写.

An acronym is a word that is formed from the letters of words in a term or phrase. For example, HTML is an acronym for Hypertext Markup Language. You should include acronyms in identifiers only when they are widely known and well understood. Acronyms differ from abbreviations in that an abbreviation shortens a single word. For example, ID is an abbreviation for identifier. In general, library names should not use abbreviations.

标识符中可以使用的两个缩写是ID和OK.在以Pascal大小写的标识符中,它们应显示为Id,然后单击确定".如果用作驼峰式标识符中的第一个单词,则它们应分别显示为id和ok.

The two abbreviations that can be used in identifiers are ID and OK. In Pascal-cased identifiers they should appear as Id, and Ok. If used as the first word in a camel-cased identifier, they should appear as id and ok, respectively.

这篇关于属性"ID"的正确命名约定是什么:ID或ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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