---
title: "Basic rule for Naming Convention in C#."  
description: "Basic rule for Naming Convention in C#."  
author: "Abhishek Srivasatava"  
published: 2016-09-27  
updated: 2020-09-17  
canonical: https://www.mindstick.com/interview/23076/basic-rule-for-naming-convention-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 6 minutes  

---

# Basic rule for Naming Convention in C#.

**Naming Convention :**

**1:** Always try to choose easily readable identifiers names. eg. : Identifier to indicate girl height and boy height, we can use GirlHeight and BoyHeight.

## Example:

```
  class Databasehandler      {        int girlHeight, boyHeight; // don't use word like g, h or GlHgt etc. which is not able to
                                                  understand.    }
```

**2.** Always use brevity words.\

Brevity means concise and exact use of words in writing or speech.

**Example:**

```
 class Databasehandler      {        int girlHeight, boyHeight; // don't use phrases like elevation_above_ground     }
```

\

**3.** Avoid use of underscores, hyphens or any other non-alphanumeric characters.

Like don't use Girl_Height, Girl1 etc.

**Example:**

```
 class Databasehandler      {        int girlHeight, boyHeight; // Don't use variable name  like girl1 boy2 etc.    } 
```

**4.** Avoid use of Hungarian Notation. It creates contradiction as well as ambiguity to

the developer.\

**What is Hungarian notation?**

Notation which start like intA or charC , stringZ etc. are called Hungarian Notation.

There are some language where there is no datatype for example **Basic Combined Programming Language (BCPL)** so there is necessary to use this notation.

## Example:

```
 class Databasehandler      {        int girlHeight, boyHeight; // Don't use variable name like intGirl flootBoy2 etc.    }
```

**5.** Do not use identifiers that conflict with keywords of widely used programming

language.

Don’t use name as class, exception, string etc.

**Example:**

```
 class Databasehandler       {        string errMessage; // Don't use variable name like exception etc.    } 
```

\

**6.** Do not use abbreviation or contradiction as part of identifiers names.

**Example:**

```
class Databasehandler      {        int girlHeight, boyHeight; // Don't use variable name like girlchar, boyname.    } 
```

7. Class name should be a noun and meaningful, avoid the use of verbs. Don't prefix (“C”) in class name. Always use 1st word as a capital letter.

## Example:

```
class Databasehandler // Don't use word like CdatabaseHandler.  Don’t use handling instead of handling.    {        int girlHeight, boyHeight;     }
```

**8. Namespace:** names should be meaningful and complete. Always use 1st word

as capital letter

```
 namespace SchoolProject.{    class Databasehandler    { }};
```

9: Methods: Always use a verb-noun pair. Avoid use of camel casing.

Camel Casing means that the word which starts with small letter and then capital letter eg: iPhone. there is no use of spaces or hyphen in this format

## Example:

```
 namespace SchoolProject{    class Databasehandler          {           public void EntryDetails()  // Don’t use the word like eDetails etc.          {            //        }}}; 
```

10. Private Member Variables: if we are declaring private member variable then we should add prefix or suffix to all class level member variables with (underscore)

**eg:. m_ or _m.**

**Example:**

```
 class databasehandler    {            private int entry_;     }    
```

\

**11. Interfaces:** It should have prefix 'I' interface.

```
Example:      namespace SchoolProject{    interface IdatabaseHandler    {        int newEntry;    }
```

12. Custom Exception: We should use ‘Exception’ keyword at the end of the naming of custom Exception.

## Example:

```
class databaseException : Exception{ databaseException()        {           …        }    }   
```

## Answers

### Answer by Abhishek Srivasatava

**Naming Convention :**

**1:** Always try to choose easily readable identifiers names. eg. : Identifier to indicate girl height and boy height, we can use GirlHeight and BoyHeight.

## Example:

```
  class Databasehandler      {        int girlHeight, boyHeight; // don't use word like g, h or GlHgt etc. which is not able to
                                                  understand.    }
```

**2.** Always use brevity words.\

Brevity means concise and exact use of words in writing or speech.

**Example:**

```
 class Databasehandler      {        int girlHeight, boyHeight; // don't use phrases like elevation_above_ground     }
```

\

**3.** Avoid use of underscores, hyphens or any other non-alphanumeric characters.

Like don't use Girl_Height, Girl1 etc.

**Example:**

```
 class Databasehandler      {        int girlHeight, boyHeight; // Don't use variable name  like girl1 boy2 etc.    } 
```

**4.** Avoid use of Hungarian Notation. It creates contradiction as well as ambiguity to

the developer.\

**What is Hungarian notation?**

Notation which start like intA or charC , stringZ etc. are called Hungarian Notation.

There are some language where there is no datatype for example **Basic Combined Programming Language (BCPL)** so there is necessary to use this notation.

## Example:

```
 class Databasehandler      {        int girlHeight, boyHeight; // Don't use variable name like intGirl flootBoy2 etc.    }
```

**5.** Do not use identifiers that conflict with keywords of widely used programming

language.

Don’t use name as class, exception, string etc.

**Example:**

```
 class Databasehandler       {        string errMessage; // Don't use variable name like exception etc.    } 
```

\

**6.** Do not use abbreviation or contradiction as part of identifiers names.

**Example:**

```
class Databasehandler      {        int girlHeight, boyHeight; // Don't use variable name like girlchar, boyname.    } 
```

7. Class name should be a noun and meaningful, avoid the use of verbs. Don't prefix (“C”) in class name. Always use 1st word as a capital letter.

## Example:

```
class Databasehandler // Don't use word like CdatabaseHandler.  Don’t use handling instead of handling.    {        int girlHeight, boyHeight;     }
```

**8. Namespace:** names should be meaningful and complete. Always use 1st word

as capital letter

```
 namespace SchoolProject.{    class Databasehandler    { }};
```

9: Methods: Always use a verb-noun pair. Avoid use of camel casing.

Camel Casing means that the word which starts with small letter and then capital letter eg: iPhone. there is no use of spaces or hyphen in this format

## Example:

```
 namespace SchoolProject{    class Databasehandler          {           public void EntryDetails()  // Don’t use the word like eDetails etc.          {            //        }}}; 
```

10. Private Member Variables: if we are declaring private member variable then we should add prefix or suffix to all class level member variables with (underscore)

**eg:. m_ or _m.**

**Example:**

```
 class databasehandler    {            private int entry_;     }    
```

\

**11. Interfaces:** It should have prefix 'I' interface.

```
Example:      namespace SchoolProject{    interface IdatabaseHandler    {        int newEntry;    }
```

12. Custom Exception: We should use ‘Exception’ keyword at the end of the naming of custom Exception.

## Example:

```
class databaseException : Exception{ databaseException()        {           …        }    }   
```


---

Original Source: https://www.mindstick.com/interview/23076/basic-rule-for-naming-convention-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
