logo

1.34. C # Class

发布时间 :2025-10-25 13:34:37 UTC

Page Views: 29 views

When you define a class, you define a blueprint for data types. This does not actually define any data, but it defines what the name of the class means, that is, what the object of the class consists of and what actions can be performed on that object. Object is an instance of a class. The methods and variables that make up a class are called members of the class.

1.34.1. Definition of class #

Class is defined by keyword class start, followed by the name of the class. The body of the class, contained in 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
    }
}

Please note: