What classes are there in C#?

PHPz
Release: 2023-08-26 15:37:02
forward
1357 people have browsed it

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
   }
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!