All named members should have a short but descriptive name. Do NOT use abbreviations, except in commonly known instances. Do NOT use single letter names EXCEPT as counters in loop mechanisms (e.g. for
loops). Do NOT use underscores as whole names. UI objects should have the type name appended to the end of the descriptive name. Any kind of identifier should end with the letters ID
.
Examples:
machineNumber; SQLConnection; StudentID; STANDARD_GREETING; SaveButton; UsernameTextBox;
Namespaces should always be in PascalCase.
Example:
namespace Microsoft.VisualStudio.AwesomeStuff;
Classes should always be in PascalCase, regardless of access level.
Examples:
public class Animal { ... }
internal class Dog { ... }
private class Cat { ... }
Interfaces should always be in PascalCase, starting with the letter I
.
Example:
interface IAnimal { ... }
Methods should always be in PascalCase, regardless of access level.
Examples:
public int GetNumberOfItems(IEnumerable collectionOfItems) { ... }
private void DoSomeWork() { ... }
Parameters in constructors or methods should always be in camelCase.
Example:
public void DoSomeWork(string nameOfJob, int timesToPerform, bool isSecretWork) { ... }
Properties should always be in PascalCase, regardless of access level.
Examples:
public int ItemCount { get; set; };
private string InternalMessage { get; set; }
Private members of a class (e.g. property-backing variables) should always be in camelCase, starting with an underscore.
Example:
private string _errorMessage;
Constants should always be in ALL CAPS with underscores between each word of the name.
Example:
public const string DEFAULT_MESSAGE = "I'm sorry, Dave. I'm afraid I can't do that.";
Local variables should always be in camelCase. The var keyword will be used wherever possible for declaring local variables. Exceptions to this are numeric types, where the type should always be declared explicitly.
Example:
var thisAnimal = new Animal(); float costPerUnit = 0.00; int numberOfToesPerFoot = 5;
Enumerations declared using the enum keyword should always be in PascalCase.
Example:
public enum UserType { ... }
Boolean member names should usually begin with the item- and verb tense-appropriate form of Is to quickly indicate that the item returns a Boolean value. In some instances, this naming convention does not make sense and a more concise and appropriate name should be chosen.
Examples:
bool HasOperationCompleted(SqlConnection conn) { ... }
var _isLocalUser = true;
var containsItem = someEnumerable.Contains(expression);