COLLECTIONS
Collection Classes ============================== i) ArrayList ii) HashTable iii)SortedList iv) Queue and Stack
Collection Interfaces ============================== i) IEnumerable ii) IEnumerator And IDictionaryEnumerator iii)ICollection iv) IList v) IDictionary
Members of IEnumerable ============================== i) Current () : Returns the current object in the collection. ii) MoveNext() : Used to move the position of the enumerator to the next item in the collection. iii)Reset() : Used to reset the position of the iterator to the first element of the collection. Note: The IEnumerable interface is associated with IEnumerator. ==== Methods of IEnumerable ============================== IEnumerable interface has one method. i) GetEnumerator():It provides a forward-only read-only cursor for a set of items.
Members of ICollection ============================== i) Count() : Used to get the number of items in the collection. ii) CopyTo() : Used to copy the collection items to an array starting at a specified position in this array. iii)IsSynchronized and SyncRoot are used to set and get the synchronization object and status of the collection. Note: The ICollection interface derives from the IEnumerable interface so it inherits the GetEnumerator method. ====
Members of IList ============================== i) Item() : Used to get an object from a collection at a specified index. ii) Add() : Used to add an item to the end of the list. iii)Insert() : Used to insert an item into the collection at a specified position. iv) Remove() : Used to remove an item from the collection. v) RemoveAt() : Used to remove an item from the collection at a specified index. vi) Contains() : Used to find out whether an item is contained in the collection. vii)IndexOf() : Used to get the index of an item within a list. v) Clear() : Used to remove all items from the collection.
Property of IList ============================== i) IsReadOnly() : Determine if a list is read-only. ii)IsFixedSize() : Determine if a list is of fixed size. Note: The IList interface inherits the members of both ICollection and IEnumerable. ====
Members of IDictionary ============================== i) Item() : Used to get an item from the collection based on its associated key. ii) Add() : Used to add an item into the collection by passing in the key and value. iii)Remove() : Used to remove an item from the collection by passing the key of the value. iv) Keys()&Values() : Used to get a collection of all keys and values in this dictionary. v) Contains() : Used to find out whether a key is associated in a collection. vi) Clear() : Used to remove all items from the collection. vii)GetEnumerator() : Used to get a specified enumerator of IDictionaryEnumerator. Note: ==== The IDictionary interface derives from the ICollection interface so it inherits all of its methods and properties, as well as those of the basic interface IEnumerable.
Members of IDictionaryEnumerator ============================== i) Entry() : Used to retrieve both the key and value at the current position in the dictionary. ii) Key() : Used to retrieve the key at the current position. ü Value() : Used to retrieve the value at the current position. Note: The IDictionaryEnumerator interface derives from IEnumerator. ====
ArrayList: ============================== The ArrayList is a collection class that models a dynamic array, whose size increases as required when new objects are added to the array. Namespace : System.Collections Implementing Interfaces : ICollection, IList, ICloneable, IConvertible
Characteristics: ============================== i) To store dynamic data use the arraylist class. So it is compact memory usage. ii) The search for an item in an arraylist is performed sequentially. So it is slow. iii)Type of Access is indexed.
HashTable: ============================== A HashTable is a collection of key-value pairs implemented using a hash table algorithm. Namespace : System.Collections Implementing Interfaces : ICollection, IDictionary
Characteristics: ============================== i) Search is very fast. ii) HashTables are big and fast. iii)High Memory usage. iv) Type of Access is using the hash of a key value.
SortedList: ============================== A SortedList is a collection class that holds a set of key-value pairs. Namespace : System.Collections Implementing Interfaces : ICollection, IDictionary
Characteristics: ============================== i) A Sorted List may not contain duplicate keys. A HashTable can have duplicate keys. ii) Search is fast. iii)Medium Memory usage. iv) Type of Access is using the index and key value.
Queue and Stack: ============================== i) Queue uses a First-In-First-Out (FIFO) Algorithm. ii) Stack uses a Last-In-First-Out (LIFO) Algorithm.
Methods of Queue: ============================== i) Enqueue (Add an item) ii)Dequeue (Remove the first item)
Methods of Stack: ============================== i) Push (Add an item) ii)Pop (Remove the last item)
Click Here for Collections Example...
|
No responses found. Be the first to respond and make money from revenue sharing program.
|