-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
  • 19,902
  • 11
  • 86
  • 275
Angel Gonzalez Pena
  • 145
  • 1
  • 1
  • 10

1 Answers1

1

With Linq and the Intersect method:

C = A.Intersect(B)
Max Xapi
  • 660
  • 8
  • 20