Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
we have two types members in c#

1.static members
2.instance members


when class loaded at the time static members are internalized or invoked either in compile time or runtime?

and also those static members stored in heap or stack?

What I have tried:

when class loaded at the time static members are internalized or invoked either in compile time or runtime?

and also those static members stored in heap or stack?
Posted
Updated 30-Dec-17 23:18pm
Comments
Krishna Veni 31-Dec-17 2:31am    
please help me

1 solution

Static members are initialized before the static member is accessed for the first time and before the static constructor, if there is one, is called.
So until you access the class at run time, the static member are not initialized, but they will be before any code in the class containing them is executed, so that your code can rely on them being ready.

Stack or heap? Heap. Think about it: there is only one static object, and there are as many stacks as there are threads. The only place the static object can reside is the heap, and it is referenced via the Type Object for the compiled class (which is used to track inheritance among other things) so that is it never garbage collected until the AppDomain is unloaded.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900