7

Does VB.Net have an equivealent for c#'s yield break?

Public Function Validate(validationContext As ValidationContext) 
                As IEnumerable(Of ValidationResult) 
                Implements IValidatableObject.Validate
    '' what is equivalent to C#'s - yield break;
End Function
afuzzyllama
  • 6,538
  • 5
  • 47
  • 64
Chris_web
  • 743
  • 3
  • 10
  • 19
  • Check this: http://stackoverflow.com/a/382189/1341477 – Dave Williams Jun 27 '13 at 13:39
  • 2
    @JimMischel I think he's asking what is the equivalent syntax in VB, not what does it do. – John Kraft Jun 27 '13 at 13:40
  • 1
    Yeah, I got trigger happy. According to http://msdn.microsoft.com/en-us/library/vstudio/dscyy5s0.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-3, "You can use an Exit Function or Return statement (Visual Basic) or yield break statement (C#) to end the iteration." – Jim Mischel Jun 27 '13 at 13:42
  • These other questions are not remotely duplicates of this one. – Konrad Rudolph Jun 28 '13 at 14:28

1 Answers1

12

Yield exists in vb.net, as you can see in msdn

And you'll even find information on yield break :

You can use an Exit Function or Return statement (Visual Basic) or yield break statement (C#) to end the iteration.

Raphaël Althaus
  • 59,727
  • 6
  • 96
  • 122
  • 2
    After all attempts, compiler is happy with 'Return Nothing' – Chris_web Jun 27 '13 at 13:48
  • 1
    If I remember correctly, though, I don't think the actual `Yield` statement was added to VB.NET until .NET 4.5 (Visual Studio 2012). – valverij Jun 28 '13 at 15:07
  • 2
    No, `Return Nothing` doesn't break the iterator, it returns the default value of the data type, so if your iterator function returns `IEnumerable(Of Integer)` then `Return Nothing` returns 0. Use `Exit Function` to break the iterator. – Nostromo Jan 16 '20 at 16:15