I'm trying to explain boxing to a junior colleague.
The canonical example seems to be ArrayList
. For example:
But this has been superseded by List<T>
from C# 2, when generics were introduced (as explained in this answer).
So, in the age of generics, under what circumstances would I find myself boxing values?
Edit: To be clear, I'm not asking whether it is still possible to use boxing. I'm asking why we would use boxing now that generics have made ArrayList
obsolete.
Edit 2: I thought this was already clear, but I'm also not asking about the difference between an ArrayList
and a List<T>
. In fact, this question is entirely premised on the fact that I appreciate that generics mean we don't have to use an ArrayList
, and we therefore don't need to box values in these circumstances.