【问题标题】:converting validation from the free pdf asp.net mvc nerdinner (c#) to vb.net将验证从免费的 pdf asp.net mvc nerdinner (c#) 转换为 vb.net
【发布时间】:2009-05-27 21:45:31
【问题描述】:

您如何将此代码转换为 vb.net,因为 vb 没有 yield 关键字

谢谢

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;
}

【问题讨论】:

    标签: c# asp.net-mvc vb.net


    【解决方案1】:

    创建一个列表,而不是执行“yield return”,只需将这些规则添加到列表中。然后只需简单地返回列表。

    【讨论】:

    • 这行得通,但需要注意的是它不是延迟执行——即,CPU 必须先完成列表才能返回,而不是按要求计算列表中的每个项目。也就是说,在 VB.NET 中没有直接等效的“收益回报”,所以这是最快的选择。
    猜你喜欢
    • 1970-01-01
    • 2010-12-14
    • 1970-01-01
    • 2010-12-21
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多