Reputation: 42660
I figure I'm missing something here but I was just reading this article by jesse liberty regarding Reactive Extensions for .Net. His example is for Window Phone 7 using Silverlight, but Silverlight also has an ObservableCollection data type. So I'm trying to figure out what the difference ... perhaps the Rx is more powerful?
Can anyone compare and contrast these? When would I use one over the other?
Thanks
Upvotes: 5
Views: 963
Reputation: 22744
ObservableCollection and RX have only one thing in common - the word Observable.
That's it.
ObservableCollection is an UI-oriented class that implements INotifyCollectionChanged.
Reactive Extensions is a library built around the IObservable and IObserver interfaces, which are not directly related to the UI (thought it can be used successfully in UI scenarios).
Upvotes: 7
Reputation: 74654
It's an unfortunate name, but here's a collection that is both Observable in the Silverlight sense, as well as the Rx.NET sense:
https://github.com/xpaulbettsx/ReactiveUI/blob/master/ReactiveUI/ReactiveCollection.cs
For example:
myReactiveCollection.ItemsAdded
.Subscribe(x => Console.WriteLine("{0} was added", x));
This class is part of ReactiveUI, which is an M-V-VM framework that integrates with Rx.NET (full disclosure: I wrote it)
Upvotes: 3