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||۱۲۸||Yes||No||No||No||[A-z]||No|
C# Coding Standards and Naming Conventions
۱٫ Do use PascalCasing for class names and method names:
۲٫ Do use camelCasing for method arguments and local variables:
۳٫ 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.
۴٫ Do not use Screaming Caps for constants or readonly variables:
۵٫ Use meaningful names for variables. The following example uses seattleCustomers for customers who are located in Seattle:
۶٫ Avoid using Abbreviations. Exceptions: abbreviations commonly used as names, such as Id, Xml, Ftp, Uri.
۷٫ Do use PascalCasing for abbreviations 3 characters or more (2 chars are both uppercase):
۸٫ 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).
۹٫ 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.
۱۰٫ Do use implicit type var for local variable declarations. Exception: primitive types (int, string, double, etc) use predefined names.
۱۲٫ Do prefix interfaces with the letter I. Interface names are noun (phrases) or adjectives.
۱۳٫ 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.
۱۴٫ Do organize namespaces with a clearly defined structure:
۱۵٫ 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.
۱۶٫ Do declare all member variables at the top of a class, with static variables at the very top.
۱۷٫ 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’).
۱۸٫ Do not explicitly specify a type of an enum or values of enums (except bit fields):
۲۰٫ Do not use “Flag” or “Flags” suffixes in enum type names:
۲۱٫ Do use suffix EventArgs at creation of the new classes comprising the information on event:
۲۲٫ 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.
۲۳٫ Do not create names of parameters in methods (or constructors) which differ only by the register:
occurrence of conflict situations.
۲۴٫ 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.
۲۵٫ 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 در یک پروژه عملی