我有两个问题
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/