I have a List of Int64 (List A) that needs to moved infront of another List (Int64) (List B).
List B will ALWAYS contain the numbers from List A.
So say the List A has the following numbers:
1, 4, 5
List B could then look something like this:
1, 9, 5, 2, 10, 15, 4
The end result should then look like this:
1, 4, 5, 9, 2, 10, 15
What is the easiest way of moving the numbers from the first list to the front of the second list?
I thought about removing all List A numbers from List B and then adding them to front again, but I can't seem to grasp my head around the programming itself.
Yo can try the following:
var result = listA.Concat(listB.Except(listA)).ToList();
// Gives: 1, 4, 5, 9, 2, 10, 15, 14
Except
removes all elements of listA
from listB
. Concat
then adds them to the front of the list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With