c# - 从电子邮件列表中获取唯一域的列表

标签 c# .net linq .net-core

例如,我有一个电子邮件列表,例如:

<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f899b89c9795999196d69b9795" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1c7e5c7873717d7572327f7371" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d0b390b4bfbdb1b9befeb3bfbd" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f094b0838592de949f9d91999ec2de939f9d" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3c5b7c4f495e125853515d55520e125f5351" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="166e56717b777f7a3875797b" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="532a13323d323f2a273a30207d343e323a3f7d303c3e" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d2a892abb3babdbdfcb1bdbf" rel="noreferrer noopener nofollow">[email protected]</a>

我想获取@之后的部分,并且只获取一次(唯一)。

到目前为止我已经尝试过:

string[] campusCup(string[] emails)
{
    var hs = new HashSet<string>();

    var emailList = emails.Select(x => new { domain = x.Split('@')[1] })
                            .Where(x => hs.Add(x.domain) && Write(x.domain));

    return hs.ToArray();
}

当我尝试调试它时,我的解决方案似乎没有选择任何内容。

最佳答案

试试这个:

var domains = emails.Select(email => email.Split('@')[1]).Distinct().ToList();

关于c# - 从电子邮件列表中获取唯一域的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51102298/

相关文章:

.net - .NET有没有 "advanced"测试框架?

c# - LINQ 对象 : How to join different properties in the same List of objects

c# - ASP.NET 用户/成员/MembershipUser/安全/主体/配置文件...帮助

c# - 距离未知时如何绕角旋转

c# - 将 Base64 显示为图像的快速性能方法

c# - 如何获得看起来像没有选项卡的 TabControl 的控件?

c# - 更改其他进程的键盘布局

C# - Linq - XPathSelectElement 每次都返回相同的结果

c# - 创建一个枚举

c# - 如何在 WinForms 客户端应用程序中使用命令模式?