Manually merging a list in C # with duplicates

I am trying to figure out how to handle combining or combining two lists that may have duplicates. For example, List1 has {A, B, C} and List2 has {B, C, D}. I tried using the Union operation and got a new list with values ​​(A, B, C, D). However, I need the values ​​of B and C from the second list, not the first. Is there a way to specify a union method that duplicates the value to use.

The code I'm using now is

var newList = List1.Union<Object>(List2).ToList();

Thanks for any help. Javid

+3
source share
4 answers

A connection is logically a dialing operation. Concat is what you are looking for.

List1.Concat(List2)
+7
source

:

var newList = List2.Union<Object>(List1).ToList(); 

.. , , , ?

EDIT:

, -, . , , .

, , List.Sort(), , ? , , , - .

+2

You tried

var newList = List2.Union<Object>(List1).ToList();
0
source

You can look Joining your listings. After this operation, you will have "join" objects for each duplicate to check ...

0
source

Source: https://habr.com/ru/post/1741958/


All Articles