Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging Two ObservableCollections

I have two Observable Collections that I need to merge into one collection.

This arises because I have two methods, getTasks(staffID) which returns an ObservableCollection and getTasks(teamID) which selects the staff and pulls back the staff tasks.

For the teams I will have multiple small observableCollections, I just want to merge them.

like image 895
DavidA Avatar asked Aug 18 '09 13:08

DavidA


1 Answers

This is what worked for me:

Concat or Union, but the result is a IEnumerable, so it needs to be converted back into an ObservableCollection:

var result = new ObservableCollection<T>(list1.Concat(list2));
like image 66
Samo Avatar answered Oct 09 '22 09:10

Samo