C#.Net code naming conventions

 

Naming convention is set of rules that are applied to the declarations while programming.
Due to this developer should concentrate more issues rather than syntax and able to use tools for code analysis.

1)What is Pascal Casing?

First letter of every word is capitalized. There is no space between words
Ex: ShivaLingaPrasad

2)What is Camel Casing?


It is same as pascal casing only difference is first letter of the first word is small letter. There is no space between words
ex: iPhone , eBay 

3)Namespace naming convention in C#.Net?


<Company>.(<Product>|<Technology>)[.<Feature>][.<Subnamespace>]
Give company name as prefix to the namespace, Sometimes one project using many companies name spaces so that it is very useful
Do use pascal casing for namespace components
Ex: Microsoft.Office.PowerPoint

4)Names of Assemblies and DLLs naming convention in C#.Net??

Following same Name convention like Namespace 

5)Class naming convention in C#.Net?


Class name always follow Pascalccasing.

Recommended to use nouns for class name.

Recommended to use derived class name suffix with base class name.

Ex:ArgumentOutOfRangeException 

6)Structure naming convention in C#.Net?


Structures following the same convention followed by classes.

7)Interface naming convention in C#.Net?

Always interface name prefix with 'I'. Name always follow pascal casing and no space between words.

Difference between class name interface name is only I (prefix to the interface name)
Ex: IComponent


8)Methods naming convention in C#.Net?

Methods always represent some action. so that always recommended to use verb or  verb phrases for method names. 

For methods name also use pascal casing

Ex: public void PutData() {} 

9)Properties naming convention in C#.Net?


Properties always represent some feature. so that always recommended to use  noun phrase or adjective names for  Properties name.

if Properties are collections use plural phrase instead of singular

 public ArrayList StudentNames
        {
            get;
            set;
        }

if Properties are Boolean use prefix "Is", "Can", or "Has" 

Always use pascal casing. 

10)Events naming convention in C#.Net?


Events always represent the action that is either performed or performing. so that events are named with verbs.

Always give events names with before and after, using the present and past tenses.

Always use pascal casing. 

11)Method parameters naming convention in C#.Net?


Use camel casing for method arguments.
Give parameters name based on usage , not based on type
 
void CalculateSquare(int valParameter){ }

12)Local variables naming convention in C#.Net?


Use camel casing for Local variable declarations.
Give parameters name based on usage , not based on type
pArray = new int[5] {-3, -1, -2, -3, -4}; 

13)Resources files key-values naming convention in C#.Net?

Always use pascal casing for  in resource keys.
Provide descriptive in general english.
<it id="AppleID" value="apple" description="my favorite fruit" />

14)Enum naming convention in C#.Net?


Enum name always use pascal casing.
Enum name should be singular not plural
Enum members also follow pascal casing - I am not sure

ex: enum Color { Red,Green,Blue}


15)Abstract class naming convention in C#.Net?

Abstract class follow same naming convention followed by class.
Virtual methods,Abstract methods naming convention in C#.Net?
Virtual and Abstract methods follow the same syntax followed general class methods.


16)Object naming convention in C#.Net?

Always use camel casing.
var keyword variable declarations
 
17)Comments naming convention in C#.Net?


Begin comment text with an uppercase letter.End comment text with a period.


Thanks for visiting this blog. How is the content?. Your comment is great gift to my work. Cheers.

No comments:

Post a Comment