Skip to content

33. Class System.Collections.Generic.List<T>

February 12, 2011

The class System.Collections.ArrayList used in .NET 1.x development can be replaced with an optimised version introduced in .NET 2.0 System.Collections.Generic.List<T>.

The class List<T> implements the interfaces IList<T> and ICollection<T>, IEnumerable<T>, IList, ICollection and IEnumerable.

Example: Insert two objects of type person in a strongly typed list.

Insert two Person objects in a strongly typed list

In a general fashion, the allocation/freeing of memory resources when updating the number of elements generates a performance hit for the system. One reaches this state when allocating more memory than is required to anticipate possible insertions. The same way, the disallocation of memory resources happens when a certain number of elements have been deleted. The number of elements in the list is managed by the property Count, the number of elements that the list can contain without having to allocate new memory resources is represented by the property Capacity.
The value of Capacity is always higher or equal to Count. Any time, the method void TrimExcess() can be called to delete the not used elements.

Happy Excessive Programing! =)


From → OOP

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: