How will an object with a value type and a reference type be stored in .NET?

In .NET, an integer data type is a value type (stack), and String is a reference type (heap).

So, if class A has an integer and an object of type string in it, and class B creates an object of class A, then how will this object of class A be stored in memory? On the stack or on the heap?

This was asked in my interview with Microsoft. You need to understand how I lived.

+3
source share
4 answers

Eric Lippert just wrote about this :

It is simply not true that the choice of whether to use a stack or a heap is of fundamental importance with regard to the type of stored thing.

True story:

" Microsoft # CLR, , , lambda , , , ".

, , , . , .

+9

, . , , .

; . , Rex M.

+3

, , .

, A .

0

It was just a tough question. I think a question has been asked of you to test your knowledge of dotnet classes. Classes are referential. So, in simple words, it will go to the heap section.

0
source

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


All Articles