I have a some small doubt with classes and objects.
In a class I have 10 to 20 methods, (shared below)
public class tstCls
{
public void a1()
{ }
void a2()
{ }
void a3()
{ }
void a4()
{ }
void a5()
{ }
void a6()
{ }
void a7()
{ }
void a8()
{ }
void a9()
{ }
}
When creating a object for the above class. How many methods will be stored in memory? Only the calling method or all the methods.
static void Main(string[] args)
{
tstCls objcls = new tstCls();
objcls.a1();
}
Can you please help me on the above scenario.
None.
The methods are not created in memory when you instantiate an object, only the fields and properties are.
The assembly that contains the methods is loaded whenever any part of the assembly is referenced.
Methods get compiled into memory only when they are called. The JIT (Just-In-Time compiler) turns the methods from IL into machine code at that moment in time.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments