为什么struct不能有无参数的构造函数?
为CLR做什么或为什么不允许这样做的问题是什么?
请解释一下,因为我不明白.
解决方法
我不能有一个显式的无参数构造函数,只有隐式的构造函数才能将所有成员初始化为默认值.
Although the CLR allows it,C# does not allow structs to have a default parameterless constructor. The reason is that,for a value type,compilers by default neither generate a default constructor,nor do they generate a call to the default constructor. So,even if you happened to define a default constructor,it will not be called and that will only confuse you. To avoid such problems,the C# compiler disallows definition of a default constructor by the user. And because it doesn’t generate a default constructor,you can’t initialize fields when defining them,…
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|