是Java静态块相当于一个C#静态构造一个? [英] Is a Java static block equivalent to a C# static constructor?
本文介绍了是Java静态块相当于一个C#静态构造一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是一个C#静态构造函数和一个Java静态块?
What is the real difference between a C# static constructor and a Java static block?
他们都必须是无参数的真正区别。
他们都只能调用一次,当第一次使用了相关的类。
They both must be parameterless. They are both called only once, when the related class is first used.
我缺少的东西,或者是他们同样的事情,只是名称不同?
Am I missing something, or are they the same thing, just with different names?
推荐答案
他们是等价的,除了C#类只能有一个静态构造函数(加上静态字段初始化)。
They are equivalent, except that a C# class can only have one static constructor (plus static field initializers).
此外,在C#中,静态
构造将适用的 beforefieldinit
标志。
Also, in C#, a static
constructor will apply the beforefieldinit
flag.
这篇关于是Java静态块相当于一个C#静态构造一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文