Cod*_*nis 9 vb.net ienumerable iterator yield-return
可能重复:
VB.NET中的产量
在C#中,当编写返回a的函数时IEnumerble<>,您可以使用yield return返回枚举的单个项目并yield break;表示没有剩余项目.做同样事情的VB.NET语法是什么?
NerdDinner代码中的一个示例:
public IEnumerable<RuleViolation> GetRuleViolations() {
if (String.IsNullOrEmpty(Title))
yield return new RuleViolation("Title required","Title");
if (String.IsNullOrEmpty(Description))
yield return new RuleViolation("Description required","Description");
if (String.IsNullOrEmpty(HostedBy))
yield return new RuleViolation("HostedBy required", "HostedBy");
if (String.IsNullOrEmpty(Address))
yield return new RuleViolation("Address required", "Address");
if (String.IsNullOrEmpty(Country))
yield return new RuleViolation("Country required", "Country");
if (String.IsNullOrEmpty(ContactPhone))
yield return new RuleViolation("Phone# required", "ContactPhone");
if (!PhoneValidator.IsValidNumber(ContactPhone, Country))
yield return new RuleViolation("Phone# does not match country", "ContactPhone");
yield break;
}
Run Code Online (Sandbox Code Playgroud)
这将C#转换为VB.NET工具会出现"YieldStatement is unsupported"错误.
| 归档时间: |
|
| 查看次数: |
14205 次 |
| 最近记录: |