简体   繁体   中英

How to use Pascal Casing and Camel Casing for Short Acronyms in C#?

A short acronym is like ID or DB which has only 2 characters.

How to name these when pascal casing (for Property or Class names) and for Camel Casing (input prameters, arguments)?

I know each Company has their own standard but I'm looking for a more generally acceptable standard.

eg when pascal casing:

ProductID or ProductId?
IDOfProduct or IdOfProduct?
DBRate or DbRate?
RateOfDB or RateOfDb?

and when camel casing:

productID or productId?
idOfProduct?
dbRate?
rateOfDb or rateOfDB?

According to MSDN (or Msdn :)

  • Do capitalize both characters of two-character acronyms, except the first word of a camel-cased identifier.

  • Do capitalize only the first character of acronyms with three or more characters, except the first word of a camel-cased identifier.

  • Do not capitalize any of the characters of any acronyms, whatever their length, at the beginning of a camel-cased identifier.

More info here

It doesn't matter.

This is really personal preference. When a short acronym finishes a name, I capitalize both:

testDB

or

TestDB

When a short acronym begins a name, I only capitilze the first because I think it makes it more readable:

dbTest

or

DbTest

It's all about readability . Whatever you choose to do, do it consistently.

Do capitalize both characters of two-character acronyms, except the first word of a camel-cased identifier.

A property named DBRate is an example of a short acronym (DB) used as the first word of a Pascal-cased identifier. A parameter named ioChannel is an example of a short acronym (IO) used as the first word of a camel-cased identifier.

Check this link.

http://msdn.microsoft.com/en-us/library/ms229043(v=vs.100).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM