If the objects in both collections are reference types (e.g., a class
rather than a struct
), and the same instance is added to both collections, the collections then have a reference to the same object instance. A change made in either place will automatically be reflected in the other.
If, however, you replace the object instance in one collection with another object instance, the other collection will not know about it: it will still hold a reference to the original object. To get around that, you'll want to use the observer pattern.
Depending on the semantics of your collection and your requirements, you could
- use the CLR's
ObservableCollection<T>
- roll your own implementation,
- use the C5 collections library (my favorite) which provides observable collections for all its collection types.