8,497
社区成员
发帖
与我相关
我的任务
分享
public class Result
{
public string Url { get; set; }
}
public class UnKeyDomain
{
public string domain { get; set; }
}
var resultList = new List<Result>();
resultList.Add((new Result() { Url = "www.google.com" }));
resultList.Add((new Result() { Url = "www.baidu.com" }));
resultList.Add((new Result() { Url = "www.bing.com" }));
resultList.Add((new Result() { Url = "www.yahoo.com" }));
var unKeyDomainList = new List<UnKeyDomain>();
unKeyDomainList.Add((new UnKeyDomain() { domain = "yahoo.com" }));
//我现在要在resultList 中排除掉含有unKeyDomainList 域名的数据,返回:
// resultList.Add((new Result() { Url = "www.google.com" }));
// resultList.Add((new Result() { Url = "www.baidu.com" }));
// resultList.Add((new Result() { Url = "www.bing.com" }));
public class Result
{
public string Url { get; set; }
}
public class UnKeyDomain
{
public string domain { get; set; }
}
class Program
{
static void Main(string[] args)
{
try
{
var resultList = new List<Result>();
resultList.Add((new Result() { Url = "www.google.com" }));
resultList.Add((new Result() { Url = "www.baidu.com" }));
resultList.Add((new Result() { Url = "www.bing.com" }));
resultList.Add((new Result() { Url = "www.yahoo.com" }));
var unKeyDomainList = new List<UnKeyDomain>();
unKeyDomainList.Add((new UnKeyDomain() { domain = "yahoo.com" }));
//我现在要在resultList 中排除掉含有unKeyDomainList 域名的数据,返回:
//resultList.Add((new Result() { Url = "www.google.com" }));
//resultList.Add((new Result() { Url = "www.baidu.com" }));
//resultList.Add((new Result() { Url = "www.bing.com" }));
resultList = resultList.Where(i => !i.Url.Contains(unKeyDomainList[0].domain)).ToList();
foreach (var item in resultList)//打印resultList集合
{
Console.WriteLine(item.Url);
}
Console.WriteLine("执行成功!");
Console.ReadLine();
}
catch
{
Console.WriteLine("执行失败!");
Console.ReadLine();
}
}
}
resultList = resultList.Where(s => !unKeyDomainList.Any(ukd => s.Url.Contains(ukd.domain))).ToList();