DEV Community

loading...

Discussion on: Interview question: heap vs stack (C#)

Collapse
mcanon profile image
mc-anon

Thanks for writing this! I've been reading about this topic all day and it has been rather confusing to be honest. I have seen read many sources that do assert that the main difference is that value types go to the stack, and reference types to the heap.

This may seem like a silly question (I know, there are no silly questions in programming), but if I declare a global variable of type int, will that be stored on the heap?

Collapse
tyrrrz profile image
Alexey Golub Author

There are no "global" variables in C#, as everything is part of some class (or struct). But if it's a field in a class then it's most likely going to be on the heap.

Forem Open with the Forem app