Reputation: 1493
I have two Lists: ListA and ListB. Some of the elements in ListB are contained in ListA, which contains also elements from other lists. My question is:
How can I find the indexes of the elements of ListA contained in ListB?
Lets say
ListA = [A B D E J]
ListB = [A B C H J K L M N O P R Q Z]
I want this result:
ListC = [0 1 -1 -1 4]
or just
ListC = [0 1 4]
Thank you!
Upvotes: 0
Views: 38
Reputation: 5827
ListA.Select(x => ListB.IndexOf(x))
To understand this code you need to be able to understand both Select
and IndexOf
. Both are simple, common and important, so make sure you find out how to use them.
Upvotes: 3