Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I recently started working with Unity3D and primarily scripting with C#. As, I normally program in Java, the differences aren't too great but I still referred to a crash course just to make sure I am on the right track.

However, My biggest curiosity with C# is that is capitalises the first letter its method names (eg. java: getPrime() C#: GetPrime() aka: Pascal Case?). Is there a good reason for this? I understand from the crash course page that I read that apparently it's convention for .Net and I have no way of ever changing it, but I am curious to hear why it was done like this as opposed to the normal (relative?) camel case that, say, Java uses.

Note: I understand that languages have their own coding conventions (python methods are all lower case which also applies in this question) but I've never really understood why it isn't formalised into a standard.

share|improve this question
I really don't think you can look at camelCase and PascalCase and underscore_case and say that one of them is normal (even relatively normal) and the others not. As @dasblinkenlight said, it's an arbitrary choice. The only thing making you think that C#'s convention unusual is that you "normally program in Java", and are thus accustomed to the arbitrary choice made for Java. – Carson63000 Aug 2 '12 at 5:00
Use JavaScript instead.. for Unity3D :) – Lipis Aug 7 '12 at 0:54
@Lipis Why for - other than personal taste? ;-) – AedonEtLIRA Aug 7 '12 at 14:58
@AedonEtLIRA totally personal.. never mind :) Enjoy Unity no matter what language.. you'll end up using.. – Lipis Aug 7 '12 at 22:13
@Lipis So far it's great. Tons of bells and whistles and I haven't yet dropped money on it yet. But I do prefer the structured style of C# (c/c++) and java. – AedonEtLIRA Aug 7 '12 at 22:29
up vote 23 down vote accepted

Naming conventions represent arbitrary choices of their publisher. There is nothing in the language itself to prohibit you from naming your methods the way you do in Java: as long as the first character is a letter/underscore, and all other characters are letters, digits, or underscores, C# is not going to complain. However, the class libraries that come with .NET follow a convention that Microsoft has adopted internally. Microsoft also published these guidelines, so that others may choose to adopt them for their own class libraries too. Although it is your choice to follow or to ignore Microsoft's guidelines, familiarization with your code by others may go faster if you follow the same naming guidelines.

share|improve this answer
However there is usually some rationale behind a convention, and when I read "Is there a good reason for this?" I understand it as a question about WHY not WHAT. – greenoldman Oct 8 '13 at 9:42

Perhaps due to Pascal / Delphi influence. The creator of C# and Delphi was the same person after all (Anders Hejlsberg).

Delphi coding conventions by and large happen to be the same as C#'s in this aspect; see or - coincidence?

share|improve this answer
A +1 for this because it gives what may be the actual reason why this particular arbitrary choice was made for C#. – Le Comte du Merde-fou Jul 3 '13 at 20:11

In addition to the other answers made, having camel case for methods means that they can conflict with names for private members, parameters and method variables that use camel case for their naming. In Java (and C# 1.0) this isn't terribly common since delegate use is awkward and rare. In modern C# it's not exactly common, but it's also not unheard-of.

share|improve this answer
The underscore should not be used in C# private fields (see, e.g), but it's controversial and often found. – Jens Aug 2 '12 at 7:05
relying on casing to distinguish between language constructs is a really bad idea, regardless of whether the language allows you to do it or not. – gbjbaanb Aug 2 '12 at 10:11
@Telastyn that statement is pretty shocking. Most of the .NET class library uses that convention. – MattDavey Aug 2 '12 at 14:31
@Dunk how is it suddenly my convention? I was merely passing a comment, I don't have an opinion on this matter either way :) – MattDavey Aug 2 '12 at 18:58
@MarjanVenema : not sure what you are talking about but C# is quite case sensitive and you can certainly have collisions between similarly cased members. This gets fun and exciting when you have actual case INsensitive languages like VB.NET you are working with on a library level. – Wyatt Barnett Jul 3 '13 at 18:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.