Answer the question
In order to leave comments, you need to log in
Where is a static class variable stored in .Net?
I wondered where a static variable is stored in .net? But I didn't find the exact answer...
As far as I understood, they are stored in the object of the type, which means in the heap... Therefore, every time they are accessed, they are unpacked?
Answer the question
In order to leave comments, you need to log in
google help:
stackoverflow.com/questions/337019/hows-memory-all...
No, there is no unpacking. Unpacking is needed when explicitly converting an object into a value - the ldfld operation immediately receives the value.
Implementation details (where it is stored) are irrelevant in this plan.
The static variable is stored in 1 instance in memory, and the assembly meta data on the HDD.
Object - stores all static fields and methods (Flyweight pattern).
Instance - stores all non-static fields of the class. (otherwise it would store immutable copies of duplicate data).
On Youtube channel ITVDN, a lecture from the course "C # Basic" is available for free, take a look.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question