简体   繁体   English

LINQ to Object比较两个不同值的整数列表

[英]LINQ to Object comparing two lists of integer for different values

I accept both C# and VB.NET suggestion, even though I'm writing an app in VB.NET 我接受C#和VB.NET建议,即使我在VB.NET中编写应用程序

I have two lists of intergers 我有两个整数列表

  • List1 {1,2,3,5} 清单1 {1,2,3,5}
  • List2 {2,4,6,7} 清单2 {2,4,6,7}

I want to have new List3 {4,6,7} which is composed of elements of List2 that are not in List1. 我想要新的List3 {4,6,7},它由List2中不在List1中的元素组成。 I know I can write a nice For Each loop for this but I want it done in LINQ I've been looking for such methods at Enumerable Methods , but I can't find it. 我知道我可以为此编写一个很好的For Each循环,但我希望它在LINQ中完成我一直在Enumerable Methods中寻找这样的方法 ,但我找不到它。

Is there any way to do with LINQ? LINQ有什么办法吗?

List2.Except(List1)
var List3 = List2.Except(List1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM