Narazana
Narazana

Reputation: 1950

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

I have two lists of intergers

I want to have new List3 {4,6,7} which is composed of elements of List2 that are not in 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.

Is there any way to do with LINQ?

Upvotes: 3

Views: 2628

Answers (2)

sblom
sblom

Reputation: 27363

var List3 = List2.Except(List1);

Upvotes: 3

Joachim VR
Joachim VR

Reputation: 2340

List2.Except(List1)

Upvotes: 9

Related Questions