Skip to main content
 首页 » 编程设计

c#之foreach循环

2024年02月24日22yxwkf

我有两个问题

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) { ... }