'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.

e.g. 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?


Solution 1:[1]

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.

Solution 2:[2]

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

Solution 3:[3]

Capitalization of ID has been debated a lot with no conclusive answer.

The API design guidelines have the Pascal as Id and the camel as id

https://docs.microsoft.com/dotnet/standard/design-guidelines/capitalization-conventions#capitalizing-compound-words-and-common-terms

ID in the context of software engineering is typically the abbreviation for identifier (as opposed to ID acronym for Identification Document in other, IRL, contexts). As such an abbreviation should indeed follow the casing shown by the Pascal and camel examples of the reference above. However outside of programming context while still in the context of computer science, ID has been broadly used and accepted as the de-facto casing for the abbreviation. The ID capitalization even made it to the Microsoft Writing Style Guide:

https://docs.microsoft.com/style-guide/developer-content/reference-documentation

Which happens to match what the Pascal casing would have been for a two letter acronym (which it isn't!). Thus ID bled back into software variable names and we have the modern mess of lack of consistency.

So as unsatisfying an answer as it is, the casing of ID in Pascal cased variable names does come down to a question of personal, or project, preference. As a rule stickler, my personal preference is Id for code and ID for any user content. But as a collaborator, I'm for whatever the team can agree on.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 James Hill
Solution 2 Harsh
Solution 3 David Burg