我希望简化以下包含 foreach 循环的代码,以最小化迭代和/或提高性能,因为每次迭代都会创建 LINQ 和集合:
foreach (Contact contact in Contacts) // phone contacts, around 500-1000
{
IEnumerable<ContactEmailAddress> emails = contact.EmailAddresses; // each has multiple emails
foreach (Friend parseUser in parseUsers) // could be many thousands
{
if (emails.Where(e => e.EmailAddress == parseUser.Email).ToList().Count > 0)
{
parseUser.AddContact(contact); // function call
verifiedUsers.Add(parseUser); // add to my new aggregated list
}
}
}
谢谢。