Where is the object located in C #?

I am a Java programmer, and I know that in java objects are stored on the heap. Just for curiosity, I wanted where the objects are in C #.

+4
source share
5 answers
  • For reference types: on the heap
  • For value types: on the stack for local variables and method parameters or on the heap for members of the reference type
+7
source

C # does not indicate where an object or value should be stored. It simply defines the semantics of reference types and value types.

The Microsoft .NET CLR stores the values ​​(instances of value types) contained in local variables on the stack, and instances of reference types (objects) and nonlocal value types on the heap. However, as stated earlier, other C # language implementations are free to store things at their discretion as long as they correspond to the semantics of values ​​and references defined by the C # Language Specification.

+5
source

detailed explanation,

C # Heap (ing) Vs Stack (ing) in .NET: Part I Matthew Cochran January 14, 2006 http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_memory01122006130034PM/csharp_memory.aspx

+1
source

Objects are also stored on the heap in C #.

0
source

Types of links stored in a managed heap.

The types of default values ​​are stored on the stack.

Value types can also be stored on the heap in several cases:

  • During boxing (casting value type for an interface, downcasting value type for an object, etc.).
  • If the value type is a member of the reference type
  • If the value type uses in closure
0
source

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


All Articles