I have 2 List lists. Both lists have all elements of the same type, but the type can differ each time I need to perform the following. And each list is sorted.
These lists are the X values for a chart, each list is the X values for a series in the chart. I need to merge them to get the combined values. The simple example is X is DateTime objects and one list has just weekdays while the other has weekend days too.
The more complex example is where the same X value can occur multiple times. So if it's occurs twice in one list and three times in the other, I need it three times in the final list.
Is there an easier way than just walking the two lists and inserting new entries from list 2 into list one as needed?
And as I walk the list, which is typed as objects as it can be a number, string, or DateTime, is there some library call I can call to get an inequality on each pair of objects?
Update:
Let me add a couple of things based on the comments below:
- I don't know the type at compile time. This is to handle chart data and the X values can be strings, numbers (int or float), DateTime, and possibly a couple of other types. All I know is that the values on any given run will all be the same type.
- What I need is different than AddRange() or Union(). If list A has 5 twice and list B has 5 three times, I need it three times in the final list.
- I don't have a code sample because that's what I'm trying to figure out, what should the code for this be.
- Basically what I need is Union() but where it handles the case of duplicate entries in each list.