C# Coding Standards and Naming Conventions
in this article we talk about naming conventions and standards and some law about it , any programmer that want to join a big team in all over the world should know this conventions truely , all of this conventions are base of team working for develope a big size of softwares .
|Object Name||Notation||Length||Plural||Prefix||Suffix||Abbrevia tion||Char Mask||Unde rsco res|
|Enum type name||PascalCase||128||Yes||No||No||No||[A-z]||No|
C# Coding Standards and Naming Conventions
1. Do use PascalCasing for class names and method names:
2. Do use camelCasing for method arguments and local variables:
3. Do not use Hungarian notation or any other type identification in identifiers
Why: consistent with the Microsoft’s .NET Framework and Visual Studio IDE makes determining types very easy
(via tooltips). In general you want to avoid type indicators in any identifier.
4. Do not use Screaming Caps for constants or readonly variables:
5. Use meaningful names for variables. The following example uses seattleCustomers for customers who are located in Seattle:
6. Avoid using Abbreviations. Exceptions: abbreviations commonly used as names, such as Id, Xml, Ftp, Uri.
7. Do use PascalCasing for abbreviations 3 characters or more (2 chars are both uppercase):
8. Do not use Underscores in identifiers. Exception: you can prefix private fields with an underscore:
Why: consistent with the Microsoft’s .NET Framework and makes code more natural to read (without ‘slur’).
Also avoids underline stress (inability to see underline).
9. Do use predefined type names (C# aliases) like int, float, and string for local, parameter and member declarations. Do use .NET Framework names like Int32, Single, String when accessing the type’s static members like Int32.TryParse or String.Join.
10. Do use implicit type var for local variable declarations. Exception: primitive types (int, string, double, etc) use predefined names.
12. Do prefix interfaces with the letter I. Interface names are noun (phrases) or adjectives.
13. Do name source files according to their main classes. Exception: file names with partial classes reflect their source or purpose, e.g. designer, generated, etc.
14. Do organize namespaces with a clearly defined structure:
15. Do vertically align curly brackets:
// Correct class Program
static void Main(string args)
Why: Microsoft has a different standard, but developers have overwhelmingly preferred vertically aligned brackets.
16. Do declare all member variables at the top of a class, with static variables at the very top.
17. Do use singular names for enums. Exception: bit field enums.
Why: consistent with the Microsoft’s .NET Framework and makes the code more natural to read. Plural flags because enum can hold multiple values (using bitwise ‘OR’).
18. Do not explicitly specify a type of an enum or values of enums (except bit fields):
20. Do not use “Flag” or “Flags” suffixes in enum type names:
21. Do use suffix EventArgs at creation of the new classes comprising the information on event:
22. Do name event handlers (delegates used as types of events) with the “EventHandler” suffix, as shown in the following example:
public delegate void ReadBarcodeEventHandler(object sender, ReadBarcodeEventArgs e); Why: consistent with the Microsoft’s .NET Framework and easy to read.
23. Do not create names of parameters in methods (or constructors) which differ only by the register:
occurrence of conflict situations.
24. DO use two parameters named sender and e in event handlers. The sender parameter represents the object that raised the event. The sender parameter is typically of type object, even if it is possible to employ a more specific type.
Why: consistent with the Microsoft’s .NET Framework and consistent with prior rule of no type indicators in identifiers.
25. Do use suffix Exception at creation of the new classes comprising the information on exception:
C# Coding Standards and Naming Conventions C# Coding Standards and Naming Conventions C# Coding Standards and Naming ConventionsC# Coding Standards and Naming Conventions C# Coding Standards and Naming Conventions
asp.net core in action with mohammad ghorbani
اصول پایه ای asp.net core در یک پروژه عملی