惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Commits to openclaw:main
Recent Commits to openclaw:main
SecWiki News
SecWiki News
Webroot Blog
Webroot Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
N
News and Events Feed by Topic
Recent Announcements
Recent Announcements
Help Net Security
Help Net Security
Jina AI
Jina AI
O
OpenAI News
雷峰网
雷峰网
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园 - 三生石上(FineUI控件)
W
WeLiveSecurity
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
IT之家
IT之家
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Vercel News
Vercel News
N
News and Events Feed by Topic
T
The Exploit Database - CXSecurity.com
爱范儿
爱范儿
Recorded Future
Recorded Future
Google Online Security Blog
Google Online Security Blog
TaoSecurity Blog
TaoSecurity Blog
美团技术团队
Engineering at Meta
Engineering at Meta
Security Latest
Security Latest
V
V2EX
T
Tailwind CSS Blog
P
Privacy & Cybersecurity Law Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Schneier on Security
B
Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 【当耐特】
PCI Perspectives
PCI Perspectives
GbyAI
GbyAI
I
Intezer
Spread Privacy
Spread Privacy
Security Archives - TechRepublic
Security Archives - TechRepublic
Cloudbric
Cloudbric
V
Visual Studio Blog
MongoDB | Blog
MongoDB | Blog
Forbes - Security
Forbes - Security
The Last Watchdog
The Last Watchdog
aimingoo的专栏
aimingoo的专栏
C
CERT Recently Published Vulnerability Notes
A
About on SuperTechFans
罗磊的独立博客

博客园 - 陳龑

怎么把网站全站变黑白(如地震哀悼网站变黑白), 要兼容所有主流浏览器 学习新技术的 10 个建议 解决 PHP Fatal error: Call-time pass-by-reference has been removed mysql下float类型使用一些误差详解 windows 如何查看端口占用情况 Page类与Control类的生命周期(life cycle)比较总结[转] WCF中的Dispose[转] 面向程序员的数据库访问性能优化法则 http https无缝切换 ADO.NET 的最佳实践技巧 模板引擎的一种实现 虚拟主机时常出现MAC验证失败错误之解决方法(转) 转载 软件架构师应该具备的素质(Enterprise Solution Architects and Leadership) asp.net Cookies 转码的问题 中文丢失 - 陳龑 .NET面试题,看看你的水平[转] - 陳龑 - 博客园 js在firefox中的问题 - 陳龑 - 博客园 “提高一下dotnet程序的效率一”中关于exception的问题 在VS2005中使用原来的IIS调试Web程序(像VS2003一样) 用正则表达式提取url中的Querystring参数 - 陳龑 - 博客园
静态构造函数
陳龑 · 2008-07-11 · via 博客园 - 陳龑

静态构造函数用于初始化任何静态数据,或用于执行仅需执行一次的特定操作。在创建第一个实例或引用任何静态成员之前,将自动调用静态构造函数。

class SimpleClass
{
// Static constructor
static SimpleClass()
{
//...
}
}

静态构造函数具有以下特点:

  • 静态构造函数既没有访问修饰符,也没有参数。

  • 在创建第一个实例或引用任何静态成员之前,将自动调用静态构造函数来初始化类。

  • 无法直接调用静态构造函数。

  • 在程序中,用户无法控制何时执行静态构造函数。

  • 静态构造函数的典型用途是:当类使用日志文件时,将使用这种构造函数向日志文件中写入项。

  • 静态构造函数在为非托管代码创建包装类时也很有用,此时该构造函数可以调用 LoadLibrary 方法。

在此示例中,类 Bus 有一个静态构造函数和一个静态成员 Drive()。当调用 Drive() 时,将调用静态构造函数来初始化类。

C# 
public class Bus
            {
            // Static constructor:
            static Bus()
            {
            System.Console.WriteLine("The static constructor invoked.");
            }
            public static void Drive()
            {
            System.Console.WriteLine("The Drive method invoked.");
            }
            }
            class TestBus
            {
            static void Main()
            {
            Bus.Drive();
            }
            }