Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the modified keyword knowledge points of the definition of class members in C #

Shulou Source: shulou.com Published: 2022-06-03 05:04:43 09月28日 Update

This article shows you the definition of C#class members modified keyword knowledge points, concise and easy to understand, absolutely can make you shine, through the detailed introduction of this article I hope you can gain something.

There are four main ones:

public--Members can be accessed by any code.

private--Members are accessible only by code in the class (this keyword is used by default if no keyword is used).

internal--A member can only be accessed by code internal to the assembly (project) in which it is defined.

protected A member can only be accessed by code in a class or derived class.

Specific to the field there are two additional:

readonly--Indicates that this field can only be assigned during constructor execution or by an initialization assignment statement.

static--Static fields must be accessed through the class that defines them, not through an object instance of that class.

const--keyword const to create a constant value.

Content expansion:

Modifiers that can be applied to classes and structs

(1)abstract: Indicates that a class can only be a base class of other classes.

Can be used with classes, methods, properties, indexers, and events. Use the abstract modifier in a class declaration to indicate that a class can only be a base class of other classes. Members marked as abstract or contained in an abstract class must be implemented by a class derived from the abstract class.

(2)sealed: Specifies that the class cannot be inherited.

Can be applied to classes, instance methods, and attributes. Sealed classes cannot be inherited. A sealed method overrides a method in the base class, but it cannot itself be further overridden in any derived class. The sealed modifier must always be used with override when applied to a method or property.

Using the sealed modifier in a class declaration prevents inheritance of this class

(3)static: Declares a member that belongs to the type itself rather than to a specific object.

Declares static members that belong to the type itself rather than to a specific object. Can be used with classes, fields, methods, properties, operators, events, and constructors, but not with indexers, destructors, or types other than classes.

(4)partial: Defines partial classes and structures throughout the same assembly.

Partial type definitions allow you to split the definition of a class, structure, or interface into multiple files.

The above content is the definition of class members in C#. What are the key words of knowledge? Have you learned knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.

Tags: Members methods keys knowledge code fields properties types keywords content functions objects structures keywords knowledge points Centers events instances skills instructions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Linux Shulou Technology Microsoft Redmi