System.Object as the escape valve to make things as general as possible doesn’t only have bad characteristics with regard to compile-time safety; we have to give in on performance, as well. Not only does the runtime type checking required by cast instructions induce additional cost, keeping a value type object as a
System.Object causes boxing. Recall how boxing involves wrapping a value in a heap-allocated box, therefore adding pressure to the garbage collector. And when the value needs to be retrieved with its original type, the symmetric unboxing operation occurs. Figure 15.2 illustrates boxing and unboxing.