c# - Why are structs stored on the stack while classes get stored on the heap(.NET)? -
I know that one of the differences between classes and structs is that the struct examples are stack and square examples (objects) Stored on that stack stored on Since classes and stranks are very similar. Does anyone know the difference for this particular glory?
(edit to cover points in the comment) After emphasizing : There are differences and similarities between the value-type and context-type, but those differences are nothing with heaps of verses , and everything has to do with copy-meaning science reference versus -Semantics Specifically, if we do: Then talking about the same copy of "first" and "second" (end edit) The whole "Go to Value Type Stack" thing ... - Value type No < Then they go to the heap (the last two are actually only foreign examples of the first) i.e.
fu first = new fu {bar = 123}; Fu seconds = First; foo ? Or different copies? It just happens that the stack handling is a convenient and effective method of value-type in the form of value. But this is an implementation description.
square fu {int i; // Stack on static zero Foo () {int i = 0; // on the heap to capture // ... Action series = Representative {Console.WriteLine (i);}}} Fixed IEnumerable & lt; int & gt; Foo () {// i.I. // // return yield on the heap to block the heater i < In addition to this, Eric Lipert (as previously mentioned) is on this topic
Comments
Post a Comment