简体   繁体   English

我想在两个列表之间应用除外。 一个列表是MailAddress格式,另一个是String(转换为列表))

[英]I want to apply Except between two lists. One list is in MailAddress format and other is a String (Converted to list))

I want to apply Except between two lists. 我想在两个列表之间应用Except One list is in MailAddress format and other is a String (Converted to list))? 一个列表是MailAddress格式,另一个是String (转换为列表))?

         List<MailAddress> toemails = new List<MailAddress>();
            //List<String> emailsFrom = address.Split(';').ToList();
            List<string> temp1 = new List<string>();
            List<MailAddress> temp2 = new List<MailAddress>();
            List<MailAddress> temp3 = new List<MailAddress>();

      //message.to gives me a list of messages (outgoing)
            foreach (var e in message.To)
            {
                temp2.Add(e);
            }

           //result contains a list of emails fetched (count=7)
            var result = from lst in ListofEmails where lst.ToLower().Length < 50 select lst;
            temp1 = result.ToList();

            //(Not able to understand this, how to proceed)

            // toemails = temp2.Except(temp1.);
            // MailMessage msg = new MailMessage();

The output, result of Except , should be a list of MailAddress objects. 输出, Except结果,应该是MailAddress对象的列表。

No need to use Except, just use basic LINQ: 不需要使用Except,只需使用基本的LINQ:

Since temp1 contains the e-mail addresses... 由于temp1包含电子邮件地址......

toemails = temp2.Where(email =>
          !temp1.Any(e => e.Equals(email.Address, StringComparison.OrdinalIgnoreCase))).ToList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我有两个字符串列表,如何从每个列表索引中创建一个字符串? - I have two Lists of string how can i create a string from each List index with the other one? 在linq中连接两个列表,在一个C#Linq中将一个字段作为数组包含在一个列表中,将简单字符串包含在另一个列表中 - joining two lists in linq with a field as an array in one list and simple string in other list in C# Linq C#我有两个列表。 我想比较一下 - C# I have two lists. I want to compare them 如何比较两个列表,其中一个列表以另一个列表开头,并且只返回“悬垂”元素? - How do I compare two lists where one list starts with the other, and only return the "overhang" elements? 将两个列表合并为一个列表 - Join two lists into one list 按属性对对象列表进行分组,拆分为多个列表。 - Grouping a List of objects by property, split into multiple lists. 如何在Automapper中将两个列表映射到一个列表? - How do I map two lists to one list in Automapper? 无法使用。除了两个列表<String> - Unable to use use .Except on two List<String> 通过重新排列其他两个列表来创建新列表 - Creating a new List by rearranging two other lists 在LINQ中加入两个列表,并写入其他列表 - Join two lists in LINQ, writing into other list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM