Types of Structure Values

I know that struct is a value type, which means it is defined on the stack.

But I can do A a = new A (); (Of course, my structure). and it is defined on the heap, and only the reference variable is on the stack.

Can you please explain this to me.

+3
source share
5 answers

Value types are sometimes stored on the stack. This is a complex topic and, as a rule, the exact storage of a variable (stack or heap) is not related to programming problems. The real difference between values ​​and reference types is their behavior (for example, value types are always copied by value).

Eric Lippert describes this issue in detail:

+4

, .
CPU / .

, . , lamda , , , , , , .

++ # new . .

new . - .

:

  • , . .
  • , . . , escape, , , .

, .

+2

(A a = new A();) . , . -, . "new" #/. NET. .

+1

, " ", . , :

  • : " ", " ".
  • . , . , , .
  • . ? , , . - . ? ? , #, .
+1

A a = new A(); (, ). , .

A - , , A - , . A, .

If you need further analysis, you will need to publish the type definition A, as well as the whole method in which you define this variable.

0
source

Source: https://habr.com/ru/post/1780021/


All Articles