当前位置:网站首页>C#入门系列(二十四) -- 密封类和静态类
C#入门系列(二十四) -- 密封类和静态类
2022-07-19 07:36:00 【InfoQ】
密封类
sealed
sealed class 类名
{
成员列表
}
- 类是静态类;
- 类包含带有安全敏感信息的继承的受保护成员;
- 类继承多个虚成员,并且密封每个成员的开发和测试开销明显大于密封整个类;
- 类是一个要求使用反射进行快速搜索的属性。密封属性可提高反射在检索属性时的性能。
静态类
static
static class 类名
{
成员列表
}
- 静态类不可包含
sealed
或abstract
修饰符;
- 静态类不能显式指定基类或所实现接口的列表,它隐式的从object类继承;
- 静态类只能包含静态成员
- 静态类不能含有声明的可访问性为
protected
或protected internal
的成员
- 静态类没有实例构造函数。
- 静态类可以包含静态构造函数。如果非静态类包含需要进行重要的初始化的静态成员,也应定义静态构造函数。
- 静态类的成员并不会自动成为静态的,成员声明中必须显式包含一个static修饰符
class Program
{
static void Main(string[] args)
{
// 静态类使用
// 访问静态属性 输出:1
Console.WriteLine(Test.A);
// 调用静态方 输出:静态方法Show
Test.Show();
Console.ReadKey();
}
}
// 静态类
public static class Test
{
// 静态字段
public static int A = 1;
// 静态方法
public static void Show()
{
Console.WriteLine("静态方法Show");
}
}
边栏推荐
- Rotate array 189, 153, 154, 33, 81, 10.03
- 已解决(selenium报错)AttributeError: ‘WebDriver‘ object has no attribute ‘execute_cdp_cmd‘
- Favorite address and historical address of 360 browser
- SOC FPGA construction project
- The El input input box needs to support multiple inputs
- 恢复360收藏夹方法 电脑损坏、重装系统后,把360sefav_new_2021_07_16.favdb这种文件,复制到别的电脑上,含有字符new的文件是加密的无法恢复
- Relationship extraction onerel
- LeetCode 第 302 场周赛
- Leetcode-11 container with the most water (double pointer, lower_bound, upper bound)
- 【云原生Kubernetes】二进制搭建Kubernetes集群(上)——部署etcd集群和单master
猜你喜欢
Restore 360 favorites method after the computer is damaged and the system is reinstalled, put 360sefav_ new_ 2021_ 07_ 16. Favdb files are copied to other computers. Files containing the character new
Reptile exercises (II)
Dap+esb data warehouse construction process description
File upload vulnerability (I)
爬虫练习题(三)
LabVIEW在同一个面板下描绘模拟波形和数字波形
Processing of paging data
ERP能力计划与排产
MySQL learning notes - stored procedures and functions
215 "double first-class" candidates took the postgraduate entrance examination and were admitted by this "double non University"!
随机推荐
File upload vulnerability (I)
为什么把 360bookmarks拷到新电脑上无法恢复收藏夹,因为 他是加密的 您可以使用360sefav_日期.favdb和360default_ori_日期.favdb两种收藏夹备份文件导入浏览器
Cylindricity error evaluation method based on MATLAB
Dap+esb data warehouse construction process description
How to demonstrate the quality of products in reverse?
软件测试—学习笔记4
C#本质论 泛型
基于MATLAB的无限脉冲响应数字滤波器的设计与仿真
20220710 leetcode周赛:移动片段得到字符串
Fractional PID control and vector control permanent magnet motor
shell函数数组作业
数字信号处理实验二 IIR数字滤波器设计及软件实现
gin注册自定义中间件失效
Towhee daily model weekly report
nodejs定义token中间件
小白学习MySQL - Generated Columns功能
Nodejs defines token Middleware
Quickly analyze remote services to help enterprises achieve efficient customer maintenance
Why can't you restore your favorites by copying 360bookmarks to your new computer? Because it's encrypted, you can use 360sefav_ Date Favdb and 360default_ ori_ Date Favdb two favorite backup files im
Design and software implementation of FIR digital filter in Digital Signal Processing Experiment III