Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?
like image 928
The Light Avatar asked Sep 11 '12 12:09

The Light


People also ask

How do you handle acronyms in a camelCase?

When using acronyms, use Pascal case or camel case for acronyms more than two characters long. For example, use HtmlButton or htmlButton . However, you should capitalize acronyms that consist of only two characters, such as System.IO instead of System.Io . Do not use abbreviations in identifiers or parameter names.

Where can I use camel and Pascal case?

For example in Java, classes, interfaces and enums should all be written in Pascal case. Local variables declared within the body of a Java program should be written in lower camel case.

What is Pascal and camel casing?

With PascalCase, the first letter of every word in the identifier is upper case. With camelCase, the first letter of the first word in the identifier is lower case, while the first letter of every subsequent word is uppercase.

How do you use Pascal case?

Pascal case naming conventionWhen more than one word is needed to properly convey a variable's purpose, the PascalCase naming convention dictates that words be appended to each other. The use of a single uppercase letter for each additional word makes it easier to read code and discern the purpose of variables.


1 Answers

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

like image 60
mcabral Avatar answered Oct 20 '22 21:10

mcabral