我需要帮助来最小化代码。我必须检查两个不同的机器,并且需要将它们存储在同一个 matchcollection 中。我不知道该怎么做,这是我的代码,任何人都可以帮我这样做。
var patternEmail = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
MatchCollection emailCollection1;
//Get emails from ResponsibleConsultant
emailCollection1 = Regex.Matches(piWorkitem.ResponsibleConsultant, patternEmail);
foreach (Match mail in emailCollection1.Cast<Match>().Where(mail => !emailaddresses.Contains(mail.Value.ToString())))
{
emailaddresses.Add(mail.Value);
}
MatchCollection emailCollection2;
//Get emails from ResponsibleConsultant
emailCollection2 = Regex.Matches(piWorkitem.SupplierConsultant, patternEmail);
foreach (Match mail in emailCollection2.Cast<Match>().Where(mail => !emailaddresses.Contains(mail.Value.ToString())))
{
emailaddresses.Add(mail.Value);
}
帮助我避免多次重复代码。