0 Replies - 13121 Views - Last Post: 19 January 2011 - 01:24 PM

#1 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1719
  • View blog
  • Posts: 5,636
  • Joined: 25-September 09

Iterators in Visual Basic

Posted 19 January 2011 - 01:24 PM

I stumbled upon this the other day and thought others might be interested. The link has various examples of using Yield that someone might find useful.

From the article:
An iterator in Visual Basic can be used to step through collections such as lists and arrays.

An iterator function or get accessor performs a custom iteration over a collection. An iterator function uses the Yield statement to return each element in turn. When a Yield statement is reached, the current location is remembered. Execution is restarted from that location the next time the iterator function is called.

The return type of an iterator function or get accessor can be IEnumerable,IEnumerable(T), IEnumerator, or IEnumerator(T). An Iterator modifier is included in the function or get accessor declaration.

An Exit Function or Return statement can be used to end the iteration. They are the equivalent of a yield break statement in C#.

Note: Iterators were introduced in C# in Visual Studio 2005. For more information, see Iterators (C# Programming Guide).


Is This A Good Question/Topic? 2
  • +

Page 1 of 1