1. Introduction

This document provides the C# coding standards for development. The goal is to define guidelines to enforce a consistent style and formatting and help developers avoid common pitfalls and mistakes.

Consistency is the key to maintainable code. This statement is most true for naming your projects, source files, and identifiers including variables, properties, methods, parameters, classes, interfaces and namespaces.

Identifier Type Rules for Naming Example

Namespaces

Pascal Case; should start with the company namespace, followed by application "layers" as applicable

CoCon.DataServices.Contacts

Classes

Nouns in Pascal Case (also use for structs)

class Contact

Exception Classes

Pascal Case and always end with the suffix Exception

Class CoConGeneralException

Interfaces

Pascal Case prefixed by "I"

interface ICustomer

Methods

Verb or Verb/Noun pair in Pascal Case

GetBackground();

Properties

Pascal Case; do not prefix with get or set

FirstName

Constants

All uppercase with words separated by underscores

public const int MIN_WIDTH = 4;

Enum Type

Hungarian notation.

enuHatType

Enum Value

All uppercase with words separated by underscores

BOWLER

TOP_HAT

Instance Variable

Camel Case, prefixed with "m"; always make private and accessible via a property with the applicable scope.

private int mCurrentWidth;

Local Variable

Camel Case.

Always name the variable appropriately, for example what it is being used for.

Avoid using single characters like "x" or "y" except in FOR loops. Never name a variable the same as the type.

// Wrong

AppUser appUser;

// Correct

AppUser appUserData;

Parameters

Camel Case

Never name a parameter the same as the type.

public void GetContact(int contactId);

Web Page

Pascal Case (Very important since Visual Studio automatically creates Code Behind class on this name.)

ShowResults.aspx

Web page controls

Camel Case with control type prefix. For user controls, prefix an appropriately named control with "uc".

lbFirstName

txtFirstName

ddCountry

ucPopupDisplay

2.1 Case sensitivity

To avoid confusion regarding the use of case sensitivity, do not create any of the following:

3. Coding Style

Consistent layout, format, and organization are keys to creating maintainable code. The following sections describe the preferred way to implement source code to create readable, clear, and consistent code that is easy to understand and maintain.

3.1 Formatting

3.2 Commenting

3.3 Visual Studio .Net Environment Setup

4. Language Usage

4.1 Variables and Types

4.2 Exception Handling

5. Database

Given that data classes will be using inline, dynamic, parameterized SQL for database access, the following sets of guidelines will be followed.

Hope that would help somebody. you can also download the guidelines, please find it attached.