Changes

C Sharp List and ArrayList Collections

999 bytes added, 16:47, 23 January 2008
Finding Items in a C# List or ArrayList
The ''LastIndexOf()'' method returns the index value of the last item in the list to match the specified item. This is particularly useful when a list contains duplicate items.
 
== Obtaining Information About a List ==
 
There are two class memebers which are useful for obtaining information about a C# List or ArrayList collection object. The ''Capacity'' property can be used to identify how many items a collection can store without having to resize.
 
The ''Count'' property, on the other hand, identifies how many items are currently stored in the list. For obvious reasons, ''Capacity'' will always exceed ''Count''.
 
In instances where a large gap exists between ''Count'' and ''Capacity'' the excess capacity may be removed with a call the ''TrimExcess()'' method.
 
== Clearing and Trimming C# Lists ==
 
All the items in a list may be removed using the ''Clear()'' method:
 
<pre>
colorList.Clear();
</pre>
 
The ''Clear()'' method removes the items from the list and sets the ''Count'' property to zero. The ''Capacity'' property, however, remains unchanged. To remove the capacity of a list follow the ''Clear()'' method call with a call to ''TrimExcess()''.