C Sharp的结构 [英] Structures in C Sharp
本文介绍了C Sharp的结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么默认情况下会密封结构?
Why Structures are Sealed by default?
推荐答案
出于简单的原因,您不能从任何值类型派生:仅引用类型. >
造成这种情况的实际原因很复杂,并且与复制值类型时发生的情况有关:您将获得按位克隆,而不是引用副本(因为您没有对值类型的引用).因此,如果可以通过基类型复制派生结构,则将获得基类型按位复制,而不是派生类型按位复制.现在您将丢失信息.
如果您真的有需要知道的话,请Google进行价值切片",并准备小幅头痛! :laugh:
For the simple reason that you can''t derive from any value type: only reference types.
The actual reason for this is complex, and has to do with what happens when you copy a value type: you get a bitwise clone, rather than a reference copy (because you don''t have a reference to a value type). So if you could copy a derived struct via it''s base type, you would get a base type bitwise copy, rather than a derived type bitwise copy. And now you would have lost information.
If you really feel the need to know, google for "Value slicing" and be prepared to get a small headache! :laugh:
http://www.csharpfriends.com/article/getarticle.aspx?articleid = 120 [ ^ ]
上面的链接将为您提供清晰的指导.
http://www.csharpfriends.com/articles/getarticle.aspx?articleid=120[^]
The Above Link will guide you clearly.
因为默认情况下它是密封的,所以没有析构函数,因为结构是在堆栈内存中创建的.
because by default it is sealed No destructor for struct because structures are created in stack memory.
这篇关于C Sharp的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文