C# Naming Conventions based on https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/naming-guidelines
|
Identifier
|
Case
|
Example
|
|
Namespace
|
Pascal
|
System.Drawing
|
|
Class
|
Pascal
|
Customer
|
|
Class Field
|
Camel
|
_transferConfig
|
|
Interface
|
Pascal
|
IPerson
|
|
Property
|
Pascal
|
TransferConfig
|
|
Method
|
Pascal
|
TransferAccount
|
|
Parameter
|
Camel
|
accountNumber
|
|
Constant
|
Pascal
|
InfiniteThrottle
|
|
Enumeration Type
|
Pascal
|
BrowserType
|
|
Enumeration Value
|
Pascal
|
InternetExplorer
|
|
Event
|
Pascal
|
TransferComplete
|
|
Exception Class
|
Pascal
|
TransferException
|
|
Pre-Processor
|
Upper
|
NETSTANDARD
|
|
Choose names that indicate functionality
|
|
The general format for a namespace name is as follows:
|
|
<Company>.(<Project>)[.<Feature>][.<Subnamespace>]
|
|
Example: NewtonSoft.Json.Linq
|
|
Choose names that suggest large chunks of functionality.
|
|
It is advisable if assembly and DLL names follow the namespace names.
|
|
The following pattern may be followed for naming DLLs:
|
|
<Company>.<Component>.dll
|
|
Where <component> contains one or more dot separated clauses.
|
|
Example: NewtonSoft.Json.dll
|
|
Choose parameter names that indicate what data is being affected.
|
|
Good: firstName - Uses camel casing and is descriptive
|
|
Bad: decimalSalary - Name should not be based on type
|
|
Nested identifiers with clear hierarchy
|
|
Example: Menus.File.Close.Text
|
|
Use pascal cased nouns, noun phrases or adjective phrases like Customer or Invoice. This distinguishes type names from methods, which are named with verb phrases like SaveCustomer or LoadInvoice.
|
|
Use of suffixes and prefixes
|
|
Derived class should have suffix representing the base class. e,g OvalShape
|
|
TransferCompleteEventHandler – EventHandler suffix for handlers
|
|
TransferCompleteCallback – Callback suffix to delegates
|
|
TransferException – Exception suffix for deriving from Exception
|
|
AccountDictionary – Dictionary suffix for dictionary implementations
|
|
SocketStream - Stream suffix for inheriting from System.IO.Stream
|
|
Do use the prefix I for Interfaces. Example: ITransfer
|
|
Do
|
Don't
|
|
Use easily readable identifier names. Favor readability over brevity.
|
Use underscore, hyphen or Hungarian notation.
|
|
Use semantically interesting generic names. eg. GetAmountDue vs GetDecimalValue
|
Use identifiers that conflict with C#
|
|
Use acronyms only if required, and only use widely accepted ones
|
Use abbreviations as part of the identifiers.
|
|
Fields
|
|
Typically nouns or noun phrases are used as names for the fields. e.g. _salary
|
|
Properties
|
|
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.
|
|
Methods
|
|
Typically verbs or verb phrases are used as names for the methods. e.g. GetEncodingString()
|
|
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
|
|
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 enumerations
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.