C. Simplest Example

  1. The facing page shows an example of using a generic collection to obtain the benefits of strong typing and avoid the performance drag of boxing. I first instantiate an object of the class System.Collections.Generic.List, which is an expandable array, the generic equivalent of ArrayList. In its angle brackets I pass the type that I want it to hold, in this case, int. The developers of this class have written it in such a manner as to check the type that it is passed and allocate storage for holding its value, so boxing and unboxing don't take place, as you can see in Figure A-3. (We see these techniques in the next example.)

    The compiler now knows that this list accepts only integers, so storing an integer in it is allowed, as ...

Get Programming Microsoft® Composite UI Application Block and Smart Client Software Factory now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.