-3

Hi i can't speak english well forgive me if ill confuse you.

in c# i have 3 String List.

list_one: list of file address.

list_two: list of MD5 that makes with list_one.

list_three: list of MD5 that makes with list_two but in this list i collect duplicate item from list_two

Question :

How can i get each item in list_three and search that in list_two then return that index.

but i dont like to use for or foreach because that will slow my application.

how can do that with linq or lambda or any fastest way.

my lists Image

RezaParsian
  • 11
  • 1
  • 5
  • for or foreach isn't slower than linq and perfectly fine for the homework – VladL Jul 17 '20 at 16:49
  • @VladL i need do this for 11000 item.do you have any idea? – RezaParsian Jul 17 '20 at 17:00
  • 1
    "but i dont like to use for or foreach because that will slow my application." This statement seems to stem from a gross misunderstanding of something. – itsme86 Jul 17 '20 at 17:00
  • Hello, and welcome to stackoverflow. Might you please [edit] your question to include your existing code as **text** rather than as a screenshot? It's requested here not to to use images for this purpose, see [*Discourage screenshots of code and/or errors*](https://meta.stackoverflow.com/a/307500) and [*Why not upload images of code on SO when asking a question*](https://meta.stackoverflow.com/a/285557) for why. A [mcve] showing the code you have so far and where you are stuck would be ideal, and maximize your chances of getting help. – dbc Jul 17 '20 at 18:03

1 Answers1

0

No 1 foeach isn't slower. But to answer what you want is simple one liner like this.

using System.Linq;  

List<string> list = new List<string>{"a","b","c","d"};
List<string> list2 = new List<string>{"a","c"};  

var result = list.Select((a, b) => new {Value = a, Index = b})
              .Where(x => list2.Any(d => d == x.Value))
              .Select(c => c.Index).ToArray();

now result contains all the match indexes.Fiddle

Hammas
  • 1,126
  • 1
  • 12
  • 37