Get the App
SLTechnology News&Howtos  ›  Development  › 

How to define the C# class

Shulou Source: shulou.com Published: 2022-06-01 02:00:45 09月19日 Update

This article introduces the relevant knowledge of "how to define C# class". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

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.

Definition of class

The definition of a class starts with the keyword class, 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:

Class class_name

{

/ / member variables

Variable1

Variable2

...

VariableN

/ / member methods

Method1 (parameter_list)

{

/ / method body

}

Method2 (parameter_list)

{

/ / method body

}

...

MethodN (parameter_list)

{

/ / method body

}

}

Please note:

The access identifier specifies access rules for the class and its members. If not specified, the default access identifier is used. The default access identifier for the class is internal, and the default access identifier for members is private.

The data type specifies the type of the variable, and the return type specifies the data type returned by the returned method.

If you want to access members of a class, you use the dot (.) operator.

The dot operator links the names of objects and members.

This is the end of the content of "how to define C# classes". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Members types names objects data identifiers identifiers clips contents variables actual methods more knowledge operators operations utility learning and then subject Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Huawei vpn MariaDB macOS