如果在类中声明了结构,请解释结构的存储位置 [英] Please Explain where will the struct be stored if it is declared inside the Class
本文介绍了如果在类中声明了结构,请解释结构的存储位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
如果在类中声明了
,请你解释一下堆存储在哪里,因为类是引用类型,所以它得到
存储在堆上,但struct是一个值类型 - 存储在堆栈上
问候
thomson
Hi all,
Would you please explain me where will be the heap stored if it
is declared inside the Class, As class is a reference type, so it gets
stored on the heap, but struct is a value type-stored on the stack
Regards
thomson
推荐答案
不,结构不是存储在堆栈中的值类型。
结构是存储在堆栈上的值类型_if_它在方法中被声明为
局部变量。
结构是一种值类型如果结构被声明为
类的成员,则存储在堆上以及类的其余
信息。
请记住:struct就像int或double一样是一个值类型。如果你将
声明为一个类作为类成员,它存储在哪里?一个结构将
存储在同一个地方。如果你在一个方法中将int声明为局部变量,那么它存储在哪里?一个结构将存储在同一个
的地方。
No, a struct is not a value type stored on the stack.
A struct is a value type stored on the stack _if_ it is declared as a
local variable in a method.
A struct is a value type stored on the heap along with the rest of the
information for a class if the struct is declared as a member of the
class.
Remember: a struct is a value type just like an int or a double. If you
declare an int as a class member, where is it stored? A struct would be
stored in the same place. If you declare an int as a local variable in
a method, where is it stored? A struct would be stored in the same
place.
你好布鲁斯,
Frankly Iam有点混淆你的回答
发送,你可以详细解释一下
问候
thomson
Bruce Wood写道:
Hi bruce,
Frankly Iam in a bit of confusion with the answer you have
send, Can u explain me in detail
Regards
thomson
Bruce Wood wrote:
不,结构不是存储在堆栈中的值类型。
结构是值类型存储在堆栈_if_中它被声明为方法中的局部变量。
结构是存储在堆上的值类型以及其余的
信息如果结构声明为
类的成员,则为类。
请记住:结构体是一种类型,就像int或double一样。如果你将int声明为类成员,它存储在哪里?结构将存储在同一个地方。如果在方法中将int声明为局部变量,它在哪里存储?结构将存储在同一个地方。
No, a struct is not a value type stored on the stack.
A struct is a value type stored on the stack _if_ it is declared as a
local variable in a method.
A struct is a value type stored on the heap along with the rest of the
information for a class if the struct is declared as a member of the
class.
Remember: a struct is a value type just like an int or a double. If you
declare an int as a class member, where is it stored? A struct would be
stored in the same place. If you declare an int as a local variable in
a method, where is it stored? A struct would be stored in the same
place.
" thomson" < SA ********** @ yahoo.com>在消息中写道
news:11 ********************* @ g44g2000cwa.googlegro ups.com ...
"thomson" <sa**********@yahoo.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
嗨布鲁斯,
坦率地说Iam对你发送的答案有点困惑,你能详细解释一下吗
Hi bruce,
Frankly Iam in a bit of confusion with the answer you have
send, Can u explain me in detail
它没有比Jon的文章更详细:
http://yoda.arachsys.com/csharp/memory.html
这篇关于如果在类中声明了结构,请解释结构的存储位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文