Design mode (---) iterator mode

Source: Internet
Author: User

Defined:

The iterator pattern provides a way to sequentially access individual elements in an aggregated object without exposing the object's internal representation.

Because of the extensive use of iterator patterns, now high-level languages such as C#,java have already encapsulated this pattern in language. For example, in C #, foreach in.

So this is not a detailed introduction to the iterator pattern here, the following is a brief description of some of the basic knowledge that is seen in the book:

Ieumerator supports simple iterative interfaces to non-generic collections.

 Public Interface Ieumerator    {        objectget;}         BOOL MoveNext ();         void Reset ();    }

IEnumerable exposes an enumerator that supports simple iterations on a non-generic collection.

 Public Interface IEnumerable    {        ieumerator GetEnumerator ();    }

Simple example:

ilist<string> strlist =Newlist<string>(); Strlist.add ("a"); Strlist.add ("C"); Strlist. ADD ("D"); foreach(stringIteminchstrlist) {Console.WriteLine ("{0}", item); }

Design mode (---) iterator mode

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.