Use a linq query to filer the elements in the source collection.
A .Where()
query does it pretty good. You can use .Select()
or any other query too.
ObservableCollection<YourEntity> cloned = new ObservableCollection<YourEntity>(source.Where(e => e.IsSomeConditionFulfilled()));
Note that you do not clone the objects passing an IEnumerable
to the constructor of the ObservableCollection
- both collections cloned
and source
will reference the same objects. That means, if you change some YourEntity
instance properties via the source
collection (e. g. source.First().SomeProperty = SomeValue
), and this object is also contained in the cloned
collection (e. g. cloned.First() == source.First()
), then those changes will be reflected there.