Standard Naming Convention for ASP.NET and C#

For any programming language standard naming system is very import. It makes a complex system easy for others. This article describes some Standard Naming Convention. Summary of the article:

  • Standard Naming Convention in ASP.NET and C#
  • Types of Naming Convention
  • What is Camel Case?
  • What is Pascal Case?
  • What is Underscode Prefix?
  • What is Hungarian Notation?
  • Naming Convention Guidelines
  • Naming Convention of ASP.NET Control

 

Standard Naming Convention in ASP.NET and C#
In programming language naming convention have great benefits to reduce the effort needed to read and understand source code. It provides better understanding in case of reuse code after a long interval of time. It is an initial step for beginner to learn any programming language. It is a very important element. Here I have explained some criteria about naming convention for programmer.

 

Types of Naming Convention
There are different types of naming casing style. Different types of casing styles:

  • Camel Case (camelCase)
  • Pascal Case (PascalCase)
  • Underscode Prefix (_underscore)
  • Hungarian Notation

 

What is Camel Case (camelCase)?
First letter of the word is lower case and then each first letter of the part of the word is upper case.
Example: numberOfDays

 

What is Pascal Case (PascalCase)?
First letter of the word is upper case and then each first letter of the part of the word is upper case.
Example: DataTable

 

What is Underscode Prefix (_underscore)?
The word begins with underscore singe and for the rest of the word use camelCase rule.
Example: _strFirstName

 

What is Hungarian Notation?
First letter of the word is about its data type and rest of the word is camelCase. Example: iStudentNumber (i=integer)
Uppercase: All letters of the word are uppercase.
Example: ID, PI

 

Naming Convention Guidelines
Some guidelines for standard naming convention is given bellow:

  • Private Variables
    Use Camel Case for private variables.
    Example: studentName
  • Local Variables
    Use Camel Case for local variables.
    Example: studentName
  • Method
    Use Pascal Case for method name.
    Example: public string HelloWorld { … }
  • Property/ Enumerations
    Use Pascal Case for Property/Enumerations.
    Example: StudentName, StudentAddress
  • Parameter
    Use Camel Case for parameter
    Example: void SayHello(string studentName)
    {
    string fullMessage = “Hello ” + studentName;
    }
  • Namespace
    Use Pascal Case for namespace. Use the company name followed by the technology name and optionally the feature and design as follows:
    CompanyName.TechnologyName[.Feature][.Design]
    Example: CybarLab.Database, System.Web.UI, System.Windows.Forms

  • Class
    Use Pascal Case for class
    Example:
    public class HelloWorld { … }

    Interface
    Use Pascal Case for interface. Use Prefix “I” with interface name, to indicate that the type is an interface. Do not use the underscore character (_).
    Example: IServiceProvider, IMemberDirectory

  • Event
    Use Pascal Case for event.
    Example: protected void Button1_Click(object sender, EventArgs e) {…….}

    Exception
    Visual Studio .NET use “e” parameter for the event parameter to the call. To avoid conflicting please use “ex” as a standard variable name for an exception object.
    Example:
    catch (Exception ex)
    {
    // Handle Exception
    }

  • Constant
    Use uppercase for constant variables with words separated by underscores. It is recommended to use a grouping naming schema.
    Example (for group AP_WIN):
    AP_WIN_MIN_WIDTH, AP_WIN_MAX_WIDTH
  • Avoid abbreviations longer than 5 characters.
  • Avoid using abbreviations unless the full name is excessive.
    Example:
    Good: string student
    Not good: string stu
  • Use meaningful, descriptive words for naming variables.
  • All member variables must use Underscore Prefix so that they can be identified from other local variables names.
  • Avoid naming conflicts with existing .NET Framework namespaces or types.
  • Do not include the parent class name within a property name.
    Example
    Good: Customer.Name
    Not good: Customer.CustomerName
  • Use Pascal Case for file names.
  • Method name should tell you what it does.
  • A method should do only “one job”. Do not combine multiple jobs in one method even if those jobs have very few lines of code.

Naming Convention of ASP.NET Control
In general, naming ASP.NET controls is made using Camel Case naming convention, where the prefix of the name is the abbreviation of the control type name.

Hope this naming convention will help you to write efficient program in asp.net and C#. Beside that, we can follow code optimization standard and performance improvement techniques.

Comments

  1. Reply

  2. By Rashed

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *