July 2015
Intermediate to advanced
1300 pages
87h 27m
English
Unlike Visual C#, in Visual Basic the Yield statement can be executed from within a Try statement of a Try..Catch..Finally block. The following code demonstrates how to rewrite the OddNumbers iterator function including error handling:
Iterator Function OddNumbers(first As Integer, last As Integer) As IEnumerable(Of Integer) Try For number As Integer = first To last If number Mod 2 <> 0 Then 'is odd Yield number End If Next Catch ex As Exception Console.WriteLine(ex.Message) Finally Console.WriteLine("Loop completed.") End TryEnd Function
As you can see, the Yield statement ...
Read now
Unlock full access