What's the proper naming convention for a prop

2019-02-04 04:14发布

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

So .. is the naming convention ID or Id?

eg.

public int ID { get; set; }

or

public int Id { get; set; }

cheers :)

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

9条回答
Summer. ? 凉城
2楼-- · 2019-02-04 04:51

I prefer ID, also in combination with other words (e.g. CustomerID), but strictly speaking that is against the regular naming conventions.

查看更多
疯言疯语
3楼-- · 2019-02-04 04:57

The guidelines say "Id".

Fortunately the the .Net guys were kind enough to give us "naming guidelines" and not "naming laws" ;), so basically if you strongly feel that breaking a guideline rule does add more value than following it, then by all means break it, no one will take you accountable for it if they understand your reasons (like it provides more readability and accentuates the meaning of the name)

In my shop we use 'ID' even if the guidelines say 'Id', but no one, really feels guilty about it.

查看更多
The star\"
4楼-- · 2019-02-04 04:58

We around here see things like "Id" or other acronyms as a word, and "Id" is the easy one because in the banking business we do get lots of strange letter combinations. So we treat it as a word, only with the first letter capitalized, and that's how we ended up being defined in our internal coding conventions paper.

But the bottom line is: choose what convention is more comfortable for the developer team and other people that look at the source code and stick with it.

查看更多
登录 后发表回答