In this case,
obj
is stored in the heap.
public class abc
{
int a;
int b;
}
abc obj = new abc();
You may consider
obj
as a handle or a pointer(if you know C++) to the data. The data pointed to by
obj
is stored in the heap. Treat
obj
as an integral data. Consider the following code,
abc a = new abc();
abc b = a;
Now, both
a
and
b
are handles to the same data. Here this assignment is not so costly, logically, it just copies an integral value. Unlike C++, in managed languages you can't get the address of the object, as the garbage collector shall move the object. But you can use the
GetHashCode
function. So,
Console.WriteLine(a.GetHashCode() + " is equal to " + b.GetHashCode());