开发者

C# Compare two ulong lists and subtract extraneous ulong's from the unprotected one

开发者 https://www.devze.com 2023-01-28 04:54 出处:网络
I have two lists of Ulongs: The first list is a list of ulongs , the second is a (larger) list of ulongs that should be protected.

I have two lists of Ulongs:

The first list is a list of ulongs , the second is a (larger) list of ulongs that should be protected.

I want to somehow compare the two lists, and remove any ulongs that the f开发者_如何学编程irst list has that the protected list does not have (sort of garbage collection I guess).

What would be the recommended way to handle this?


What you are after is intersection.

var source = Enumerable.Range(1, 10);
var protectedSet = Enumerable.Range(9, 4);
var result = protectedSet.Intersect(source);

Which would result in:

source:

1
2
3
4
5
6
7
8
9
10

protectedSet:

9
10
11
12

result intersection:

9
10
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号