-1

I know how merge lists, but if I only want the common objects?

Example:

List A={1,2,3,4,5}
List B={4,5,6}

I know how to create this list

List C={1,2,3,4,5,4,5,6}

but I want to create this

List C={4,5}
Sinatr
  • 20,892
  • 15
  • 90
  • 319
Angel Gonzalez Pena
  • 145
  • 1
  • 1
  • 10

1 Answers1

1

With Linq and the Intersect method:

C = A.Intersect(B)
Max Xapi
  • 750
  • 8
  • 22