Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report