1. Overview of Classes
A class is an active data structure. The data and functions of a program are organized into a collection of packages of logically related data items and functions, called classes.
A class is a data structure that can store data and execute code that contains data members and function members.
Data member: Stores data related to an instance of a class or class. Data members typically emulate the nature of the real-world things that the class represents.
Function members: Execute code, usually simulating the functions and characteristics of real-world things represented by a class.
A C # class can have any number of data members and function members, and members can be any combination of 9-minute possible member types, as follows:
Data members |
Function members |
Field Constant |
Method Property Constructors destructor operators Index events |
2. Relationship between programs and classes
A running C # program is a set of interacting type objects, most of which are instances of the class. (A running program is a group of interacting objects.) )
3. Declaration Class
When we need to use a class that is not defined by C #, we need to define the class by writing the declaration of the class.
The declaration of a class defines the characteristics and members of the new class, which creates a template for creating an instance that roughly contains the name of the class, the members of the class, and the characteristics of the class.
such as: Class Myexcellentclass//class is the keyword, myexcellentclass is the name of the class
{
Member declaration
}//curly braces contain declarations of members that make up the class body. Class members can be declared in any order within the body of the class, meaning that a member's declaration can refer to another member that is defined in a later class declaration
(Note: Class declarations are sometimes referred to as "class definitions")
Classes in C #