C# dot .Net Coding Standards - Rules of ASP.Net

Definitions

Pascal Case:
Naming conventions in which multiple words are put together without
intervening underscore characters. The first letter of every word is in
uppercase; all other characters are in lowercase.

Camel Case:

Correct: EpMarcXmlFile

Incorrect: EPMARCXMLFile, EPMarcXmlFile, ep_marc_xml_file
The Camel case is similar to the Pascal case, except that the first letter of the
name is always lowercase.

Correct: errorCount

Incorrect: ErrorCount, error_count

Naming and Syntax

Use meaningful names, not cryptic abbreviations.

Avoid single letters i, k, x except in simple, non-nested loops.
Do not use Hungarian notation or variants thereof.

Examples:
No strVariable or iVariable or objVariable, etc.
Constants: Use all uppercase names, separated by underscores.

Example:
MAX_RECORDS
Namespace: Use Pascal case
Class name, Method name, Delegates, and Events: Use Pascal case
Static variables and member variables: Camel case starting with a leading
underscore.
Boolean variables: Should start with “is” or “has” and the variable should be
named for the “True” state.

Example:
private bool isThesaurusTerm = false;
Interfaces: Use Camel case with a leading “I”.

Example:
IContent
Generic variables: Use a single capital letter, such as T or K.

-->
Example:
public class FifoStack
{
public void Push( obj)
{…}
public Pop()
{…}
}
Property: Name the accessor using Pascal Case and place simple code on a
single line.

Do not prefix property names with “Get” or “Set”.

Example:
public AdaptorBase Adaptor

{

get { return _adaptor; }
private set { _adaptor = value; }

}

Indentation, Spaces and Code Structure

Do not use tab characters for indentation - use spaces (normally 4 per indent
level).
Use braces aligned with the beginning of the scope:

Example:
if ( isThesaurusProduct )
{
anArticle.addThesaurusTerms( thesList );
anArticle.addNonThesaurusTerms( nonThesList );
}
Always use curly braces { } in conditional statements and loops.
Blocks with single lines can be written in the same line.

Examples:
if ( isDebug() ) { Log( “Author: “ + authorName ); }

for ( int k = 0; k < 20; ++k ) { counter++; }
Do not start the else clause on the same line as the if clause.

Example:
if ( isCondition )
{
Do something;
}
else
{
Do something else;
}
If following an else should be placed on the same line.

Example:
if ( isCondition1 )
{
Do something;
}
else if ( isCondition2 )
{
Do something else;
}
else if ( isCondition3 )
{
Do still another thing;
}
else
{
Do something default;
}
• Use a single space after the open parenthesis, and before the closing
parenthesis.
• Do not use a space between a method name and its parenthesis.
• Do use a space between a keyword and a parenthesis.
• Use spaces after commas to separate multiple parameters.

Examples:
for ( int k = 0; k < 100; ++k ) { blah blah… }

private void DebugLog( String text )
{
}

private void DoSomething( String arg1, String arg2 )
{
DebugLog( “Some string to log.” );
}
Place C# declarations on a separate line, just above a method declaration.
Strive for single return point from function except where return is due to a
validation error in the first few lines of method.


Constructors, Finalizers, Initialization and Data Types

Do not initialize member variables in constructors unless the initial value is
different from that assigned by the language.
Always initialize all local variables.

Variables other than those for basic types should be initialized to null unless there
is a reason not to. Strings should be initialized to null and not to string.empty().
Use the C# built-in types rather than the System types unless required by external
interfaces.

Example:
int or bool rather than Int32 or Boolean

Comments

Popular posts from this blog

MIUI 7.5.5.0 upgrade to 7.5.9.0 Malmide Problem with VoLTE Solution in Red MI 3S Prime

A Story of Love

The Great VaiBhaV's Blog