价值类型 - 结构 [英] Value Types - Structures
问题描述
大家好,
微软称结构是价值类型。原始数据类型
是值类型。值类型的内存在堆栈上分配。然后
为什么我们需要新的运算符为结构值类型分配内存而不是原始数据类型的
(它们也在堆栈上分配内存)?请
帮助。
提前致谢。
Faktujaa
Hi All,
Microsoft says that structures are value types. Also primitive data types
are value types. And memory for value types is allocated on the stack. Then
why we need new operator to allocate memory for structure value types and not
for primitive data types(they r allocated memory on stack as well)??? Please
help.
Thanks in advance.
Faktujaa
推荐答案
hi
结构在堆栈上分配。
'new''的作用是将值类型'的字段初始化为null / zero
问候
Ansil
" faktujaa"写道:
hi
the struct gets allocated on the stack.
What ''new '' does is initialize the value type''s fields to null/zero
regards
Ansil
"faktujaa" wrote:
大家好,
微软称结构是价值类型。原始数据类型也是值类型。值类型的内存在堆栈上分配。然后
为什么我们需要新的运算符为结构值类型分配内存而不是原始数据类型(它们在堆栈上分配内存)?请
帮助。
提前致谢。
Faktujaa
Hi All,
Microsoft says that structures are value types. Also primitive data types
are value types. And memory for value types is allocated on the stack. Then
why we need new operator to allocate memory for structure value types and not
for primitive data types(they r allocated memory on stack as well)??? Please
help.
Thanks in advance.
Faktujaa
faktujaa< fa ****** @ discussions.microsoft.com>写道:
faktujaa <fa******@discussions.microsoft.com> wrote:
微软称结构是价值类型。原始数据类型也是值类型。值类型的内存在堆栈上分配。
值类型的内存在某些情况下仅在堆栈上分配。
参见 http://www.pobox.com/~skeet/csharp/memory.html
那么为什么我们需要新的运算符来为结构值类型分配内存而不是为原始数据类型(它们在堆栈上分配内存)?请帮忙。
Microsoft says that structures are value types. Also primitive data types
are value types. And memory for value types is allocated on the stack.
Memory for value types is only allocated on the stack in some cases.
See http://www.pobox.com/~skeet/csharp/memory.html
Then why we need new operator to allocate memory for structure value
types and not for primitive data types(they r allocated memory on
stack as well)??? Please help.
" new"只是意味着调用构造函数。它没有任何关系
分配的地方。
-
Jon Skeet - < sk***@pobox.com>
http://www.pobox。 com / ~siget
如果回复小组,请不要给我发邮件
"new" just means "call a constructor". It doesn''t have anything to do
with where things are allocated.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
新的与分配无关记忆它用于调用
构造函数。
所以通过使用带结构的new,你调用的是
结构的构造函数将其所有成员变量设置为0,false或null取决于
其类型
Nishith Pathak
" ; Jon Skeet [C#MVP]"写道:
New has nothing to do with allocation of memory. It is used to call the
constructor.
so by using the new with a structure , you are calling a constructor of the
structure which sets all its members variables to 0, false or null depending
on their type
Nishith Pathak
"Jon Skeet [C# MVP]" wrote:
faktujaa< fa ****** @ discussion.microsoft.com>写道:
faktujaa <fa******@discussions.microsoft.com> wrote:
微软称结构是价值类型。原始数据类型也是值类型。值类型的内存在堆栈上分配。
Microsoft says that structures are value types. Also primitive data types
are value types. And memory for value types is allocated on the stack.
值类型的内存在某些情况下仅在堆栈上分配。
参见 http://www.pobox.com/~skeet/csharp/memory.html
那么为什么我们需要新的运算符为结构值类型分配内存而不是原始数据类型(它们在
堆栈上分配内存)? ?请帮忙。
Then why we need new operator to allocate memory for structure value
types and not for primitive data types(they r allocated memory on
stack as well)??? Please help.
" new"只是意味着调用构造函数。没有任何事情要做。
-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复该组,请不要给我发邮件
"new" just means "call a constructor". It doesn''t have anything to do
with where things are allocated.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
这篇关于价值类型 - 结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!