I have a class below that as a method with a value type variable.
Please can some one explain me that when I create the object of the below then then what goes on the stack and what goes on the heap?
I am interested on where the variable in Method1 goes.
class A
{
public void Method1()
{
int i = 10;
}
}
A obj = new A();
obj.Method1();
You most likely don’t need to know this. To you, it’s important what the runtime does, not how it does it. And the runtime is free to chose any way to implement local variables. For all you know, they could be saved in a file (although doing that doesn’t make much sense).
If you really want to know, in general, there are several ways how a local variable can be represented in memory:
asyncmethods of C# 5.