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).
Page 1 of 1
0 Replies - 12985 Views - Last Post: 19 January 2011 - 01:24 PM
Page 1 of 1