C # object-oriented Pattern Design 18th: iterator pattern (behavior pattern)

Source: Internet
Author: User

(According to the msdn webcast courses)

Solve the collection and access problems.

The internal structures of the set mainly include linked list and sequential.

Component developers often want to provide flexible external access without exposing the internal structure of the component.

Gof: provides a method to access each element of an aggregate object sequentially without exposing the organization structure of the object.

Myenumerator inherits from ienumerator, so it is the same field and method. In mycollection, get the myenumerator object through the getenumable () method, so as to achieve sequential access to objects in mycollection.

In the C # environment, we can also use the iterator more conveniently:

In addition, after C #2.0, we can also conveniently implement the getenumerator () method:

In the iterator, we cannot change the values of individual elements in the collection object or the container structure. We should make sure that each element in the set is traversed only once.

<End>

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.