What are the classes in C#?

CsharpProgrammingServer Side Programming

When you define a class, you define a blueprint for a data type. Objects are instances of a class. The methods and variables that constitute a class are called members of the class.

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

<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 some key points about classes −

  • Access specifiers specify the access rules for the members as well as the class itself. If not mentioned, then the default access specifier for a class type is internal. Default access for the members is private.

  • Data type specifies the type of variable, and return type specifies the data type of the data the method returns, if any.

  • To access the class members, you use the dot (.) operator.

  • The dot operator links the name of an object with the name of a member.

raja
Published on 07-Aug-2018 17:55:10
Advertisements