문제

I have two lists of strings both of which are ~300,000 lines. List 1 has a few lines more than List 2. What I'm trying to do is find the strings that in List 1 but not in List 2.

Considering how many strings I have to compare, is Except() good enough or is there something better (faster)?

도움이 되었습니까?

해결책

Internally the enumerable Except extension method uses Set<T> to perform the computation. It's going to be as least as fast as any other method.

Go with list1.Except(list2).

It'll give you the best performance and the simplest code.

다른 팁

My suggestion:

    HashSet<String> hash1 = new HashSet<String>(new string[] { "a", "b", "c", "d" });
    HashSet<String> hash2 = new HashSet<String>(new string[] { "a", "b" });
    List<String> result = hash1.Except(hash2).ToList();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top