首页 新闻 会员 周边

c# 静态构造函数调用

0
悬赏园豆:30 [已解决问题] 解决于 2021-03-09 16:28

静态构造函数在使用静态成员的时候调用。但是这个例子没有先调用静态构造函数。想知道为什么

天不遮我的主页 天不遮我 | 初学一级 | 园豆:66
提问于:2021-03-09 13:53
< >
分享
最佳答案
0

Straight from ECMA-334:

17.4.5.1: "If a static constructor (§17.11) exists in the class, execution of the static field initializers occurs immediately prior to executing that static constructor. Otherwise, the static field initializers are executed at an implementation-dependent time prior to the first use of a static field of that class."

收获园豆:30
通信的搞程序 | 小虾三级 |园豆:1747 | 2021-03-09 16:08

这样就可以了 谢谢

天不遮我 | 园豆:66 (初学一级) | 2021-03-09 16:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册