比较使用C#和LINQ的两个大字符串列表的最佳方法? [英] Best way to compare two large string lists, using C# and LINQ?

查看:62
本文介绍了比较使用C#和LINQ的两个大字符串列表的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的列表(〜110,000个字符串),需要将其与类似大小的列表进行比较.

I have a large list (~ 110,000 strings), which I need to compare to a similar sized list.

列表A来自1个系统. 列表B来自一个SQL表(我只能读取,没有存储的proc等)

List A comes from 1 system. List B comes from a SQL table (I can only read, no stored procs, etc)

查找列表A中不再存在于列表B中的值的最佳方法是什么?

What is the best way to find what values are in list A, that no longer exists in list B?

数组中要处理的100,000个字符串是否很大?

Is 100,000 strings a large number to be handled in an array?

谢谢

推荐答案

所以您有两个这样的列表:

So you have two lists like so:

List<string> listA;
List<string> listB;

然后使用 Enumerable.Except :

Then use Enumerable.Except:

List<string> except = listA.Except(listB).ToList();

请注意,如果您想忽略大小写:

Note that if you want to, say, ignore case:

List<string> except = listA.Except(listB, StringComparer.OrdinalIgnoreCase).ToList();

您可以将最后一个参数替换为 IEqualityComparer<string> 您的选择.

You can replace the last parameter with an IEqualityComparer<string> of your choosing.

这篇关于比较使用C#和LINQ的两个大字符串列表的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆