Home  >  Article  >  Backend Development  >  What classes are there in C#?

What classes are there in C#?

PHPz
PHPzforward
2023-08-26 15:37:021336browse

What classes are there in C#?

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

A class definition begins with the keyword class, followed by the class name; and the class body enclosed by a pair of curly braces. The 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 important points about a class -

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

  • The data type specifies the type of the variable, and the return type specifies the data type of the data returned by the method (if any).

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

  • The dot operator combines the name of the object with the name of the member.

The above is the detailed content of What classes are there in C#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete