c# - foreach循环

标签 c# validation

我有两个问题

1) 我的界面我有一个名为 IRegister 的界面,在其中我有另一个名为 IPerson 的界面,这是正确的做法吗?

2) 我有两个 List(IRegister, IPerson) 都可以有一行或多行。

循环两个列表的最佳方法是什么?在 GetValidationRules 中?

public interface IRegister 
{
    string FirstName { get; }
    string MiddleName { get; }
    string LastName { get; }
    string EmailAddress { get; }        
    List<IPerson> Student { get; }
}


public static List<ValidationRule> GetValidationRules(List<IRegister> register)
    {
        List<ValidationRule> validationRules = new List<ValidationRule>();  



        foreach (IRegister myregister in register)
        {
            if (string.IsNullOrEmpty(myregister.FirstName))
                validationRules.Add(new ValidationRule("Reg", "Must have aFirst Name"));
            if (string.IsNullOrEmpty(myregister.LastName))
                validationRules.Add(new ValidationRule("Reg", "Must have a Last Name"));
            if (string.IsNullOrEmpty(myregister.EmailAddress))
                validationRules.Add(new ValidationRule("Reg", "Must have a Email Address"));

  IPerson here? how
        }

最佳答案

嗯,在你的标记处嵌套循环。

foreach(IPerson 窥视 myregister.Student) { ... }

关于c# - foreach循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2464481/

相关文章:

c# - 删除或修剪字符串末尾的回车符

c# - 从 Dynamics CRM 2011 插件调用 System.Diagnostics.Trace

c# - 在 ASP.NET Core 中为每个 SQL 命令打开/关闭数据库

c# - 使用 OWIN 静态文件时配置客户端缓存

c# - Web API 中的最佳/安全字符串长度

validation - bootstrap datepicker结束日期不能比开始日期晚1年以上

c# - C# 开发人员认证

javascript - 如何在reactjs的输入文本字段中允许 "dd/mm/yyyy"中的日期?

java - 关于实现服务器端和客户端验证的问题

flutter - 验证 Flutter Form 中的不可见字段