The concept of ValueType vs Reference Type is understood along with the relation to Stack vs Heap but I have a question
int - a value type, stored on the Stack
int - inherits from System.ValueType which in turn is derived from System.Object
So why is int not considered an object and placed on the managed heap?
I have seen many explanations of this on the web and it is quite confusing. The summary of which is that
value types are not objects in the eyes of CLR at the point of allocation however boxing/unboxing is
completed on the fly as soon as a method (linked with their type) is called on them. So basically
what I read into that is that
It still bodes the questions
Why is i not considered an object at
int i;
and put on the managed heap?
int - a value type, stored on the Stack
int - inherits from System.ValueType which in turn is derived from System.Object
So why is int not considered an object and placed on the managed heap?
I have seen many explanations of this on the web and it is quite confusing. The summary of which is that
value types are not objects in the eyes of CLR at the point of allocation however boxing/unboxing is
completed on the fly as soon as a method (linked with their type) is called on them. So basically
what I read into that is that
Code:
int i; //Not considered an object at this point put on Stack
string s = i.ToString(); //i boxed, value assigned to s, i unboxed again
It still bodes the questions
Why is i not considered an object at
int i;
and put on the managed heap?