我有 2 个包含电子邮件地址的列表。我使用列表联合加入他们以获得最终的电子邮件列表,但是有时,任何一个列表都可能是空的。发生的情况是,当列表为空时,它会将其添加到最终列表中作为联合之后的“”,这导致电子邮件 .Send() 在空电子邮件地址上崩溃。如何告诉工会忽略空值?这就是我所拥有的
List<string> _RecordOwnerEmailList = new List<string>();
List<string> _SubmissionEmailList = new List<string>();
List<string> _EmailList = new List<string>();
string _RecordOwnerEmails = String.Empty;
string _SubmissionEmails = String.Empty;
if (dsRecordOwner.Tables[0].Rows.Count > 0 && !String.IsNullOrEmpty(dsRecordOwner.Tables[0].Rows[0]["UpdateEmail"].ToString()))
_RecordOwnerEmails = dsRecordOwner.Tables[0].Rows[0]["UpdateEmail"].ToString().Replace(" ", "");
if (this.ID > 0)
_RecordOwnerEmailList = new List<string>(_RecordOwnerEmails.Replace(" ", "").Split(';').ToList());
if (dsEmails.Tables[0].Rows.Count > 0 && !String.IsNullOrEmpty(dsEmails.Tables[0].Rows[0]["Emails"].ToString()))
_SubmissionEmails = dsEmails.Tables[0].Rows[0]["emails"].ToString().Replace(" ", "");
_SubmissionEmailList = new List<string>(_SubmissionEmails.Replace(" ", "").Split(';').ToList());
_EmailList = _RecordOwnerEmailList.Union(_SubmissionEmailList).ToList();
string[] emails = _EmailList.ToArray();
foreach (string emailAddress in emails)
{
//send email
}