What are the rules for naming classes in C#?

CsharpProgrammingServer Side Programming

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 {

}
raja
Published on 13-Aug-2018 13:13:06
Advertisements