I have two ObservableCollection lists, that i want to unite. My naive approach was to use the Union - Method:
ObservableCollection unitedPoints = ob
The LINQ Union
extension method returns an IEnumerable. You will need to enumerate and add each item to the result collection:-
var unitedPoints = new ObservableCollection ();
foreach (var p in observableCollection1.Union(observableCollection2))
unitedPoints.Add(p);
If you'd like a ToObservableCollection then you can do:
public static class MyEnumerable
{
public static ObservableCollection ToObservableCollection(this IEnumerable source)
{
var result = new ObservableCollection ();
foreach (var item in source)
result.Add(item);
return result;
}
}
Now your line is:
var unitedPoints = observableCollection1.Union(observableCollection2).ToObservableCollection();