Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterator pattern in VB.NET (C# would use yield!) [duplicate]

How do implement the iterator pattern in VB.NET, which does not have the yield keyword?

like image 930
c00ke Avatar asked Oct 30 '08 16:10

c00ke


2 Answers

This is now supported in VS 2010 SP1, with the Async CTP, see: Iterators (C# and Visual Basic) on MSDN and download Visual Studio Async CTP (Version 3).

Code such as this, works:

Private Iterator Function SomeNumbers() As IEnumerable
    ' Use multiple yield statements.
    Yield 3
    Yield 5
    Yield 8
End Function
like image 157
Sam Saffron Avatar answered Nov 11 '22 07:11

Sam Saffron


VB.NET does not support the creation of custom iterators and thus has no equivalent to the C# yield keyword. However, you might want to look at the KB article How to make a Visual Basic .NET or Visual Basic 2005 class usable in a For Each statement for more information.

like image 32
Jasper Bekkers Avatar answered Nov 11 '22 07:11

Jasper Bekkers