【问题标题】:VB .Net equivalent for yield break;VB .Net 等效于屈服中断;
【发布时间】:2013-06-25 01:05:27
【问题描述】:

VB.Net 是否有 c# 的 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

【问题讨论】:

标签: c# .net vb.net


【解决方案1】:

yield 存在于 vb.net 中,您可以在 msdn 中看到

您甚至可以找到有关产量中断的信息:

您可以使用退出函数或返回语句 (Visual Basic) 或 yield break 语句 (C#) 结束迭代。

【讨论】:

  • 经过所有尝试,编译器对“Return Nothing”感到满意
  • 如果我没记错的话,我认为实际的 Yield 语句直到 .NET 4.5 (Visual Studio 2012) 才被添加到 VB.NET。
  • 不,Return Nothing 不会破坏迭代器,它会返回数据类型的默认值,所以如果你的迭代器函数返回IEnumerable(Of Integer) 那么Return Nothing 返回0。使用Exit Function打破迭代器。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-05
  • 2019-09-09
  • 2023-04-11
  • 2010-11-23
  • 1970-01-01
相关资源
最近更新 更多