What are the rules for naming classes in C#?


A class definition starts with the keyword class followed by the class name; and the class body enclosed by a pair of curly braces.

The following is the syntax −

<access specifier> class class_name {
   // member variables
   <access specifier> <data type> variable1;
   <access specifier> <data type> variable2;
   ...
   <access specifier> <data type> variableN;
   // member methods
   <access specifier> <return type> method1(parameter_list) {
      // method body
   }

   <access specifier> <return type> method2(parameter_list) {
   // method body
   }

   ...
   <access specifier> <return type> methodN(parameter_list) {
      // method body
   }
}

The following are the conventions for class names −

Pascal Casing

The coding conventions for a class name is the name of the class name, for example, it should being PascalCasing −

public class CalculateCost {

}

Above, the class name CalculateCost is in PascalCasing.

Noun or Noun Phrases

Prefer adding class names as noun or noun phrases −

public class Department {

}

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 21-Jun-2020

343 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements