I see this code in a c# book but i didnt understand this code, i got the meaning of boxing that mean Boxing allows value types to be implicitly treated like objects, plz explain those 2 code samples , thnxx
The result of the ToString() call in each example is the same; a string containing the value of i in the first case or obj in the second case, both being "5".
Boxing and unboxing are only relevant when talking about value types.
Value types are those types where the value is immediately known.
Reference types, on the other hand, must be de-referenced before any value can be known; they use a pointer to point to the actual value.
Boxing changes a value type in to a reference type.
Unboxing changes a previously boxed value type back to a value type.