Boxing is very similar to Java and C #. The difference is when this happens:
Character ch = 'a';
this will lead to boxing in Java because "a" is primitive and Character is a class (wrapper). In C #, this is:
Char ch = 'a';
will not lead to boxing, because Char
not a primitive type, but a value type class. To call boxing in C #, you need to pass an object of type value to object
.
object o = 'a';
Change As mentioned in a HighCore comment, in C # there is an important boxing mechanism. Entering content in a List<int>
does not cause a box and does not produce unnecessary messages, because List of int is a real list of unboxed ints.
source share