Collection Class

 <  Day Day Up  >  

The Collection object stores lists of objects. Objects in a collection can be assigned an optional key value and can be retrieved either by position (like an array) or by key (like a dictionary). Unlike the collection objects such as ArrayList and HashTable in System.Collections , values can be removed from a Collection object while the collection is being enumerated. When a value is removed from a Collection , all enumerators are automatically updated.

NOTE

The methods defined directly on Collection are 1-based, which means that items in the collection are indexed starting with 1. This is different from ArrayList or HashTable , which are 0-based and are indexed starting with 0. Note that Collection also implements the interface System.IList , which is 0-based.


 Public Sub New() 

This constructor creates a new, empty collection object.

 Public Sub Add(ByVal Item As Object, _   Optional ByVal Key As String = Nothing, _   Optional ByVal Before As Object = Nothing, _   Optional ByVal After As Object = Nothing) 

The Add method adds a new value to the collection, with an optional key specified by the Key parameter. The item can be inserted before or after an item with a particular key by supplying the Before or After parameters; Before and After cannot both be specified at the same time.

 Public Sub Remove(ByVal Index As Integer) Public Sub Remove(ByVal Key As String) 

The Remove method removes a value from the collection either by index or by key. The Collection type allows removing methods while the collection is being iterated, unlike other collection types, such as ArrayList .

 Public Property Count() As Integer 

The read-only Count property returns the number of items stored in the collection.

 Public ReadOnly Default Property Item(ByVal Index As Integer) As Object Public ReadOnly Default Property Item(ByVal Key As String) As Object 

The Item property allows fetching a particular item from the collection by index or by key.

 <  Day Day Up  >  


The Visual Basic .NET Programming Language
The Visual Basic .NET Programming Language
ISBN: 0321169514
EAN: 2147483647
Year: 2004
Pages: 173
Authors: Paul Vick

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net