What is a simple effective way to take List2 and add it to the end of List1 - but in a way that only those items that are not already in List1 before the concatenation - will be added to it?
EDIT:
I've been trying methods suggested in answers here, but I still get dupes added to List1!
This is a code example:
// Assume the existence of a class definition for 'TheObject' which contains some
// strings and some numbers.
string[] keywords = {"another", "another", "another"};
List<TheObject> tempList = new List<TheObject>();
List<TheObject> globalList = new List<TheObject>();
foreach (string keyword in keywords)
{
tempList = // code that returns a list of relevant TheObject(s) according to
// this iteration's keyword.
globalList = globalList.Union<TheObject>(tempList).ToList();
}
When debugging - after the second iteration - globalList contain two copies of the exact same object of TheObject. Same thing happens also when I try implementing Edward Brey's solution...
EDIT2:
I've modified the code that returns a new tempList, to also check if the returned items are already in the globalList (by doing !globalList.contains()) - it works now.
Though, this is a work-around...