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
unboxingnorboxing. Considering you assign tointwithout cast and, I hope, this code compiles, that means thatcls.Valueis aInteger(int)type. So assigninttoint. What happens here is a value copy.