C # differences between ienumerable, ienumerator, list, arraylist, and [] Arrays

Source: Internet
Author: User

List <t> is the generic type of arraylist, the Data Type in arraylist is object, and the Data Type in list <t> is specific. arraylist is similar to a vector, different data types can be stored in an array (converted to an object ).

Generally, use list <t> whenever possible, because arraylist must be converted once for access.

[] Arrays are similar to list <t>. The difference is that [] is fixed length, while list <t> is an array of variable length.
Icollection mainly targets static sets; ilist mainly targets dynamic Sets
Ienumerable <t> inherited from ienumerable
Icollection <t> inherited from ienumerable <t>
Ilist <t> inherited from icollection <t>
Ienumerable Interface
The set that implements the ienumerable interface indicates that this set can provide an enumerator (enumerator) object and supports the current traversal set. The ienumerable interface has only one member getenumerator () method.
The ilist interface and the arraylist class are used to implement dynamic arrays. arraylist is an implementation of ilist.

Ienumerable indicates that the object is a collection of uncertain types and supports simple iteration. It doesn't matter if it is fixed length...

Ienumerable <t> indicates that the object is a set of the specified type and supports simple iteration. It doesn't matter whether the set length is...

Icollection is a derived interface of the ienumerable interface. It indicates that the object is a set of uncertain types and supports simple iteration. It also defines the set size, enumeration number, and synchronization method, the size here refers to whether it can be fixed or not long...

Ilist is a derived interface of icollection and ienumerable. It indicates that the object is a set of uncertain types and supports simple iteration. It also defines the set size, enumeration number, and synchronization method, it can also be accessed separately based on the index. The size here can be fixed length or variable length...

The arraylist class is the implementation of the ilist interface, indicating that the object is an array of uncertain type sizes that can be dynamically increased as needed...

List
<T> the class is ilist.
<T> The Implementation of the interface is a wildcard Equivalent Class of the arraylist class and enhances the function, indicating that the object is a strongly typed list of objects that can be accessed through indexes...
More than 2.0 can completely replace arraylist, that is, arraylist has been eliminated...

Dynamic Arrays and linked lists are essentially different...
There are two-way linked list <t> generic classes in. NET 2.0 and above, which are also inherited from icollection
<T>, ienumerable <t>, icollection, ienumerable...

A set that can be traversed using foreach must inherit the ienumberable (or ienumerable <t> generic interface) interface.
The ienumberable interface has only one method:
Ienumerator getenumberator () {}// returns an ienumberator-type object, which implements the system. collection. ienumerator interface.
Interface ienumberator
{
Object current {Get ;}
Bool movenext ();
Void reset ();
}
When splicing SQL statements in a program, you can use list <t>
List <sqlparameter> List = new list <sqlparameter> ();
List. Add (New sqlparameter ("parameter name", "parameter value "));
...
Sqlparameter [] para = List. toarray ();
...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.