Show Menu

C# Naming Conventions Cheat Sheet by

C# Naming Conventions based on https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/naming-guidelines
development     programming     csharp     c-sharp

Casing Rules

Iden­tif­ier
Case
Exam­ple
Namespace
Pascal
System.Dr­awing
Class
Pascal
Customer
Class Field
Camel
_trans­fer­Config
Interface
Pascal
IPerson
Property
Pascal
Transf­erC­onfig
Method
Pascal
Transf­erA­ccount
Parameter
Camel
accoun­tNumber
Constant
Pascal
Infini­teT­hrottle
Enumer­ation Type
Pascal
Browse­rType
Enumer­ation Value
Pascal
Intern­etE­xplorer
Event
Pascal
Transf­erC­omplete
Exception Class
Pascal
Transf­erE­xce­ption
Pre-Pr­ocessor
Upper
NETSTA­NDARD
Except for parame­ters, class fields, and pre-pr­ocessor direct­ives, all other identi­fiers follow a Pascal naming conven­tion.

Namespaces

Choose names that indicate functi­onality
The general format for a namespace name is as follows:
<C­omp­any­>.(­<Pr­oje­ct>­)[.<­Fe­atu­re>­][.<­Su­bna­mes­pac­e>]
Exam­ple: Newton­Sof­t.J­son.Linq

Assemblies and DLL Names

Choose names that suggest large chunks of functi­ona­lity.
It is advisable if assembly and DLL names follow the namespace names.
The following pattern may be followed for naming DLLs:
<C­omp­any­>.<­Com­pon­ent­>.dll
Where <c­omp­one­nt> contains one or more dot separated clauses.
Exam­ple: Newton­Sof­t.J­son.dll

Parameters

Choose parameter names that indicate what data is being affected.
Good: first­Name - Uses camel casing and is descri­ptive
Bad: decim­alS­alary - Name should not be based on type

Resources

Nested identi­fiers with clear hierarchy
Exam­ple: Menus.Fi­le.C­lo­se.T­ext

Classes, Structs, and Interfaces

Use pascal cased nouns, noun phrases or adjective phrases like Customer or Invoice. This distin­guishes type names from methods, which are named with verb phrases like SaveCu­stomer or LoadIn­voice.
Use of suffixes and prefixes
Derived class should have suffix repres­enting the base class. e,g OvalShape
Transf­erC­omp­let­eEv­ent­Handler – EventH­andler suffix for handlers
Transf­erC­omp­let­eCa­llback – Callback suffix to delegates
Transf­erE­xce­ption – Exception suffix for deriving from Exception
Accoun­tDi­cti­onary – Dictionary suffix for dictionary implem­ent­ations
Socket­Stream - Stream suffix for inheriting from System.IO.Stream
Do use the prefix I for Interf­aces. Example: ITransfer
 

General Naming Conven­tions

Do
Don't
Use easily readable identifier names. Favor readab­ility over brevity.
Use unders­core, hyphen or Hungarian notation.
Use semant­ically intere­sting generic names. eg. GetAmo­untDue vs GetDec­ima­lValue
Use identi­fiers that conflict with C#
Use acronyms only if required, and only use widely accepted ones
Use abbrev­iations as part of the identi­fiers.

Types

Fields
Typically nouns or noun phrases are used as names for the fields. e.g. _salary
Prop­ert­ies
Nouns, noun phrases or adjectives are used for naming properties
Properties and Get methods should not be named alike.
Boolean properties should be named with phrases like Is or Has.
Meth­ods
Typically verbs or verb phrases are used as names for the methods. e.g. GetEnc­odi­ngS­tring()
Events
Typically verbs or verb phrases are used as names for the events.
In event handlers, use two parameter named sender and e.
Concept of before and after should be given, e.g Closing, Closed, etc

Enums

Do not use prefixes or suffixes
Usually names are plural nouns. E.g Teams, Colors
Do not use flag as suffix for the names of flag enumer­ations

Download the C# Naming Conventions Cheat Sheet

2 Pages
//media.cheatography.com/storage/thumb/gregfinzer_c-naming-conventions.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Regular Expressions Cheat Sheet

          More Cheat Sheets by GregFinzer

          RhinoMocks Cheat Sheet
          Crownpeak Input Controls Cheat Sheet