Collection
1)Collection represents a set of objects that you can access by stepping through each element in turn.
2)Object class is the base class of every type in .NET. All the collections implement IEnumerable interface that is extended by ICollection interface. IDictionary and IList are also interfaces for collection which are derived from ICollection .
3) Offering the capability to group objects in logical constructs, they improve code readability and self documentation, as well as enhance maintainability.
4)The Collection class implements the "HAS" relationship
5)For some collections, you can assign a key to any object that you put into the collection so that you can quickly retrieve the object by using the key.
6) A generic collection enforces type safety so that no other data type can be added to it. When you retrieve an element from a generic collection, you do not have to determine its data type or convert it.
7)The System.Collections.Generic namespace contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type safety and performance than non-generic strongly typed collections.
System.Object
Object class is the base class of every type. All other types directly or indirectly derive from object class.
System.Collections.IEnumerable
It exposes the enumerator, which provides a collection like behavior to user defined classes.
System.Collections.ICollection
ICollection interface specifies a method for getting the size of collection, creating enumerators on a collection and managing synchronized access to all non-generic collections. It is a base interface for classes in the System.Collections namespace.
System.Collections.IList
a)IList interface represents the collection of objects that can be individually accessed by index.
b)The implementation of IList falls into three categories: read-only, fixed-size, and variable-size. A read only IList cannot be modified. A fixed size IList does not allow the addition or removal of elements, but it allows the modification of the existing elements. A variables size IList allows the addition, removal, and modification of elements.
System.Collections.IDictionary
It represents a collection of key/value pairs. IDictionary interface is implemented by classes that supports collections of associated keys and values.
Example:-
GetEnumerator()
It returns the enumerator object that can be used to iterate through the collection. It allows using the foreach statement. Enumerators only allow reading the data in the collection.
Collapse | Copy Code
Array array = new int[] { 12, 24, 26, 35, 40, 59 };
IEnumerator iEnum = array.GetEnumerator();
string msg = "";
while (iEnum.MoveNext())
{
int n = (int)iEnum.Current;
msg += n.ToString() + "\n";
}
MessageBox.Show(msg);
Rajesh081725, if this helps please login to Mark As Answer. | Alert Moderator