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

This question already has an answer here:

I am struggling with naming convetions in C# I do not know when to use PascalCase or camelCase. I have read Microsoft's naming convention, but I got lost ther

As far as I know this is correct:

public int Number;
private int number;
public void Method();
private void method();
int number;//for any local variable

But in context of that above how should I name components in XAML: x:Name="Button" or x:Name="button". They seems to be private field so I should use camelCase, but on the other hand everywhere on the examples I see PascalCase for x:Name

I do not ask about one's habits, but orthodoxic/official/C# guru style.

share|improve this question

marked as duplicate by Carson63000, gnat, Konrad Morawski, Robert Harvey, GlenH7 Jan 23 '14 at 0:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

@Carson63000 In this link there is lot of talking, no examples. – Yoda Jan 21 '14 at 2:25
Lower case private methods are not part of official Microsoft naming convention. Personally I have never seen a C# project that use such casing. I'm not saying noone ever does, but it's kind of exotic and not recommmended by MS. – Konrad Morawski Jan 21 '14 at 11:36
The framework conventions only apply to externally visible types/members (visibility is public or protected). For the rest you can use project/company specific conventions. – CodesInChaos Jan 21 '14 at 16:06
up vote 9 down vote accepted

The conventions I use are

//non-private variable

//private variable




These are standard MS c# conventions. There is a list here. If you want something to help you keep nice clean code following conventions, consider Resharper add-on for Visual Studio

share|improve this answer
The underscore as the (private) field prefix is a controversial one. Personally I use it, but it has a suspicious taste to me and I don't follow this convention in all projects. – Konrad Morawski Jan 21 '14 at 11:32
Yeah, it does seem like a controversial subject. It is discussed briefly on MSDN. It appears the convention originated in c/c++ – James Jan 21 '14 at 11:36

I read the MS standards, a long time ago. All I remember and use is:

  • UpperCamelCase for public methods and properties
  • lowerCamelCase for protected/private methods and properties, also parameters

At the time, there was no XAML, but I don't expect precise consistency across languages.

In the end, no one's standards matter but your own. Or your team's. Or your boss's. But mostly your own.

share|improve this answer
I would mostly agree with this answer, with the caveat that anything public should follow the idioms and conventions of the language. Since a C# developer is going to expect to find VerbNoun methods (like ToString() or ExecuteNonQuery()), you should both name and capitalize your methods to meet their expectations. – mgw854 Jan 21 '14 at 4:32
Lower case for private methods?? Not in their official guidelines it isn't. I have also never seen such convention in open-source projects maintained by Microsoft (like ASP MVC or Entity Framework). – Konrad Morawski Jan 21 '14 at 11:26
@KonradMorawski: I haven't read the conventions in about a decade, thanks for the update. – Steven A. Lowe Jan 21 '14 at 18:47
Isn't "UpperCamelCase" better known as PascalCase? – Craig W Jan 21 '14 at 19:37
@CraigW: bwahahahahaha! awesome! – Steven A. Lowe Jan 21 '14 at 21:35

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