Tag: 收益率

在Nerd Dinner教程中有趣地使用C#yield关键字

通过一个教程(Professional ASP.NET MVC – Nerd Dinner),我遇到了这段代码: public IEnumerable 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# […]