C # IEnumerable, IEnumerator, List, ArrayList, [] array Calvary difference

List <T> is a generic ArrayList, ArrayList inside the data type is object, List <T> is inside some type specific, ArrayList similar vectors, different data types can be stored in an array inside (conversion object to ).

When generally used to make use of List <T>, ArrayList access should be carried out as a conversion.

[] Array of type similar to List <T>, except that [] is a fixed length, and List <T> is a variable length array
ICollection primarily for static collection; dynamic set mainly for the IList
Inherited from IEnumerable <T> IEnumerable
ICollection <T> inherits from IEnumerable <T>
IList <T> inherits from ICollection <T>
IEnumerable interface
implements a set of interfaces IEnumerable show the collection to provide a enumerator (enumerator) object that supports the current loop through the collection. IEnumerable interface has only one member GetEnumerator () method.
ArrayList class object IList interface and the dynamic arrays, ArrayList is an implementation of the IList.

IEnumerable indicates that the object is a collection of simple iteration and support the type of uncertainty is not a fixed-length do not care ...

IEnumerable <T> indicates that the object is a collection of simple iteration and supports the specified type, is not a fixed-length do not care ...



IList ICollection and IEnumerable is derived interface indicates that the object is a collection of simple iteration and support, and define the size of the collection of uncertain type, enumerator and synchronization method can also be accessed individually according to the index, the size here refers to may be the fixed length may be variable length ...

the ArrayList IList interface class is implemented, it indicates that the object type is indeterminate size can be increased dynamically as needed array ...

List <T> class is IList <T> interface implementation ArrayList class is equivalent generic class and enhanced functionality, the object indicates that the object is accessed by an index list in strongly typed .NET 2.0 ... can completely replace ArrayList above, that is to say has been eliminated ArrayList .. .

dynamic arrays and lists in nature in different ... <T> generic class of 2.0 or more has a doubly linked list LinkedList .NET, which is inherited from ICollection <T>, IEnumerable <T >, ICollection, IEnumerable .. .

can be traversed using foreach collection must inherit IEnumberable (or IEnumerable <T> generic interface).
IEnumberable interface has only one method:
the IEnumerator GetEnumberator () {} // Returns IEnumberator object type, the object is achieved System.Collection.IEnumerator interface.
IEnumberator interface
{
Object Current {GET;}
BOOL the MoveNext ();
void the Reset ();


List <SqlParameter> list=new List <SqlParameter>();
list.Add(new SqlParameter("参数名","参数值"));
...
SqlParameter[] para=list.ToArray();
...

Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2012/09/02/2667233.html

Guess you like

Origin blog.csdn.net/weixin_34261739/article/details/93495251