TL;DR: In the context of .NET class libraries, Microsoft recommends that you use Id. This is slightly counter-intuitive, since it's a rare example of an abbreviation that is allowed / recommended (abbreviations are generally frowned upon).
If we're talking about C# or .NET class library conventions, Microsoft has some fairly well defined naming guidelines available. They are well thought out, with many explanations on a variety of issues - actually, every developer should take some time to read the entire Design Guidelines section.
When it comes to acronyms, the rule of thumb is: for two letter acronyms, you tend to keep them upper case (where Pascal case is applicable), so e.g. IOStream
might be the name of a class. For a longer acronym, you lower case the rest of the acronym, e.g. XmlDocument
or HtmlParser
. This is actually a mostly unambiguous rule (there's no confusion as to where the one word ends and the next begins, unless you're chaining two-letter acronyms), and you get used to it very quickly.
So, is it ID, or Id? Well, according to Microsoft, it might not be what you think:
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.
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.
Anecdotally, I'm not actually sure when this distinction started appearing in the guidelines, but a few years back (around 3.0 / 3.5) the general naming trend in class libraries went from ID to Id.