1
int myInt
int MyInt
int my_Int
int My_Int
int myint

ProperCase, Uppercase, Lowercase, ToggleCase (for nut jobs)

There are so many possibilities and I was wondering if there is an official etiquette?

If so, who will start a "class" school for programmers?

Har
  • 4,864
  • 2
  • 19
  • 22
  • 1
    Whatever you're comfortable with, just be consistent. – MGZero Mar 22 '12 at 16:24
  • 2
    Did you consider reading the .NET documentation? there is a guide in there with all that ;) – TomTom Mar 22 '12 at 16:24
  • Have you done a search for related questions, like C# variable naming? There are many many questions on this already. – Bali C Mar 22 '12 at 16:24
  • 5
    Certainly not by prefixing ***my...***. – Tim Schmelter Mar 22 '12 at 16:25
  • possible duplicate of [What is the correct naming notation for classes, functions, variables etc in c#?](http://stackoverflow.com/questions/250423/what-is-the-correct-naming-notation-for-classes-functions-variables-etc-in-c) – Josh Lee Mar 22 '12 at 16:26

7 Answers7

3

There are two lengthily MSDN articles on the subject already, which cover pretty much all of the cases you may encounter:

Teoman Soygul
  • 25,584
  • 6
  • 69
  • 80
1

see this link http://msdn.microsoft.com/en-us/library/ms229002.aspx

Do choose easily readable identifier names. For example, a property named HorizontalAlignment is more readable in English than AlignmentHorizontal.

Do favor readability over brevity. The property name CanScrollHorizontally is better than ScrollableX (an obscure reference to the X-axis).

Do not use underscores, hyphens, or any other nonalphanumeric characters.

Do not use Hungarian notation.

DotNetUser
  • 6,494
  • 1
  • 25
  • 27
1

Official Etiquette? I think the closest you'll get to that is following the Code Analysis warning ruleset for Naming if you want. It conforms to the .NET Framework Coding Guidelines released by Microsoft. Check out the ruleset here:

http://msdn.microsoft.com/en-us/library/ms182232.aspx

Nick Nieslanik
  • 4,388
  • 23
  • 21
1

When you're coding for you self use whatever feels most normal, I use camel case 'myInt' or pascal case 'MyInt'.

But when you get a job there most likely will be a document describing how you should name your variables and define your methods.

f2lollpll
  • 997
  • 6
  • 15
0

in C# most programmers (but not all) usually go with what you call proper case.

var count = 0;
var newUser = new User();
Khalid Abuhakmeh
  • 10,709
  • 10
  • 52
  • 75
0

I recommend you to install Resharper,this will provide you the possibility of using a very good convention for identifiers in your whole code.

Daniel Conde Marin
  • 7,588
  • 4
  • 35
  • 44
0

I learned a tremendous amount from Framework Design Guidelines (2nd edition). Really everyone's answers here to your question are accurate and valid - this answer is no more correct than theirs - I'm just posting in case you are interested in a good read.

payo
  • 4,501
  • 1
  • 24
  • 32