I read What is boxing and unboxing and what are the trade offs? but can't understand one thing. Suppose I have a class:
class MyClass
{
public int Value { get; set; }
}
And I want to get value within my method:
void MyFunc(MyClass cls)
{
int i = cls.Value;
}
As a class placed in heap, I guess that Value placed in a heap too? And therefore operation
int i = cls.Value;
is unboxing? Or it's not unboxing?
It's neither
unboxing
norboxing
. Considering you assign toint
without cast and, I hope, this code compiles, that means thatcls.Value
is aInteger(int)
type. So assignint
toint
. What happens here is a value copy.