The concept of collections in C #

Source: Internet
Author: User

An object, if it can provide references to related objects, is a collection, called an enumeration, that iterates through the items in the collection. The collection must perform an interface System.Collentions.LEnumerable, lenumerable defines only one method, as follows:

Interface Ienumeralbe

{

IEnumerator GetEnumerator ();

}

IEnumerator works as follows: The object that executes the interface is associated with a collection that, at the first initialization, does not yet point to any element in the collection, and must call MoveNext () to move the enumeration so that it points to the first element in the collection. Then you get the element with the current property, and the current property returns an object reference, so you must convert its data type to the type of object you are looking for in the collection. You can take any action on the object again, and then call the MoveNext () method again to move to the next element of the collection, repeating the procedure until there is no element in the collection, and when the current property returns NULL, it indicates that the end of the collection has been reached. If you want to return to the beginning of the collection at any time, you can call the Reset () method. Note that the reset () method returns the position of the front of the collection <?xml:namespace prefix = o ns = "Urn:schemas-microsoft-com:office:office"/>

Arrays are also collections, because the foreach command can act on an array. For an enumerated array provided by the System.Array class, you can iterate through the elements in ascending order starting with the subscript 0.

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.