-1

i need a suggestion for the scenario noted below :

Contents in List A : string name , byte[] ,etc

Contents in List B : string name.

i have two collections and i need to iterate the List A with List B and check in a sequence if name from List B == name from List A .

for this i do a while loop with the sequence lengths and if /else loop for decision making if name matches or not.

i have to take decisions and other processing things for each match/unmatch item in list , also the two lists are not guaranteed of same size

is there any better way to avoid loops and if/else?

Keshav Raghav
  • 347
  • 1
  • 12

2 Answers2

0

You could use the Zip function of Enumerable after building a projection:

ListA.Select(a => a.name).Zip(ListB, (a, b) => a == b)

at the end you have a list of booleans and you could use Any to find if all items match:

ListA.Select(a => a.name).Zip(ListB, (a, b) => a == b).Where(r => r).Any()
ema
  • 5,668
  • 1
  • 25
  • 31
  • i have to take decisions and other processing for each match/unmatch item in list , also the two lists are not guaranteed of same size – Keshav Raghav Jan 04 '20 at 12:38
0

Using dictionary will solve performance issue.

Arun Kola
  • 69
  • 7