(二).net面试(static)
文章目录
- 项目地址
- 一、基础50
- 1.1 new keyword
- 1.2 static class vs. static method
- 1. static class
- 2. static method
- 3. static constructor 静态构造函数
- 4. 静态成员的声明周期
项目地址
- 教程作者:
- 教程地址:
- 代码仓库地址:
- 所用到的框架和插件:
dbt
airflow
一、基础50
1.1 new keyword
- new operator
- new modifier
- new constraint
1.2 static class vs. static method
1. static class
- 只能包含静态成员(字段、方法、属性、事件)
- 不能实例化(new 不出来)
- 不能继承或被继承(sealed + abstract 的结合体)
- 默认是 sealed(防止继承)
- 在程序第一次使用时,CLR 会初始化一次(静态构造函数)
2. static method
- 属于类的本身,而不是对象成员
- 不能访问实例成员
3. static constructor 静态构造函数
- 没有访问修饰符,没有参数
- CLR 在 第一次访问类 时调用一次
- 用于初始化静态字段
- 不能手动调用
public class Logger
{public static string FilePath;static Logger(){FilePath = "log.txt";Console.WriteLine("Static constructor called");}
}
4. 静态成员的声明周期
静态字段在 应用程序域(AppDomain)级别唯一