当在C#中被称为静态构造函数? [英] When is a static constructor called in C#?

查看:82
本文介绍了当在C#中被称为静态构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我有一个包含静态构造函数的类,是构造函数时第一次加载或包含类的程序集调用的时候,第一次引用该类被击中?

When I have class containing a static constructor, is that constructor called when the assembly containing the class is first loaded or when the first reference to that class is hit?

推荐答案

在这个类的第一次访问。

When the class is accessed for the first time.

静态构造(C#编程指南)

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

A static constructor is used to initialize any static data, or to perform a particular action that needs performed once only. It is called automatically before the first instance is created or any static members are referenced.

这篇关于当在C#中被称为静态构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆