// Use the generic List type to hold only people.
List
morePeople = new List
();
morePeople.Add(new Person());
// Use the generic List type to hold only cars.
List moreCars = new List();
// Compile-time error!
moreCars.Add(new Person());
}
Boxing Issues and Strongly Typed Collections
Strongly typed collections are found throughout the .NET base class libraries and are very useful
programming constructs. However, these custom containers do little to solve the issue of boxing
penalties. Even if you were to create a custom collection named IntCollection that was constructed
to operate only on System.Int32 data types, you would have to allocate some type of object to hold
the data (System.Array, System.Collections.ArrayList, etc.):
public class IntCollection : IEnumerable
{
private ArrayList arInts = new ArrayList();
public IntCollection() { }
Do'stlaringiz bilan baham: |