C# 修饰符(modifier)

松琦
2023-12-01

There are modifiers: private protected public internal, virtual, sealed, override, abstract, extern.

Copy from msdn.

修饰符                                   

用途                                   

访问修饰符                                                        

指定声明的类型和类型成员的可访问性。                                   

abstract                                                        

指示某个类只能是其他类的基类。                                   

async                                                        

指示所修改的方法、 lambda 表达式或匿名方法是异步的。                                   

const                                                        

指定无法修改字段或局部变量的值。                                   

事件                                                        

声明事件。                                   

extern                                                        

指示在外部实现方法。                                   

new                                                        

从基类成员隐藏继承的成员。                                   

override                                                        

提供从基类继承的虚拟成员的新实现。                                   

partial — 部分                                                        

在整个同一程序集中定义分部类、结构和方法。                                   

readonly                                                        

声明一个字段,该字段只能赋值为该声明的一部分或者在同一个类的构造函数中。                                   

sealed                                                        

指定类不能被继承。                                   

static                                                        

声明属于类型本身而不是属于特定对象的成员。                                   

unsafe                                                        

声明不安全的上下文。                                   

virtual                                                        

在派生类中声明其实现可由重写成员更改的方法或访问器。                                   

volatile                                                        

指示字段可由操作系统、硬件或并发执行线程等在程序中进行修改。                  

 

 

 

 类似资料: