为什么静态构造函数没有任何参数? [英] Why does a static constructor not have any parameters?

查看:81
本文介绍了为什么静态构造函数没有任何参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个MSDN:

静态构造函数不使用访问修饰符或没有参数.

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

A static constructor is called automatically to initialize the class before the first instance is created or any static members are referenced.

不能直接调用静态构造函数.

A static constructor cannot be called directly.

任何人都可以解释为什么静态构造函数不能有参数吗?

Can any one please explain why can't the static constructor have parameters?

推荐答案

正如MSDN所说, 在创建第一个实例之前,会自动调用静态构造函数来初始化类 .因此,您无法向其发送任何参数.

As MSDN says, A static constructor is called automatically to initialize the class before the first instance is created. Therefore you can't send it any parameters.

如果CLR必须调用静态构造函数,它将如何知道要传递哪些参数?

If the CLR must call a static constructor how will it know which parameters to pass it?

这篇关于为什么静态构造函数没有任何参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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