I have started researching Reactive extensions and I would like to know how to do the following (ill try and keep it simple):
Have a list of string (or any other type)
When an item is added to the said list, do something with it.
I have started researching Reactive extensions and I would like to know how to do the following (ill try and keep it simple):
Have a list of string (or any other type)
When an item is added to the said list, do something with it.
You can't do that with the existing List<String>
class - it doesn't provide notifications, and there's nothing that Reactive Extensions can do about that.
You might want to look at ObservableCollection<T>
though.
Get ReactiveUI, then you can use the ReactiveCollection class - then you can use the ItemsAdded Observable.
ReactiveCollection<int> someCollection;
someCollection.ItemsAdded
.Where(x => x > 100)
.Subscribe(x => Console.WriteLine("Whoa! A big item was added!"));
If you have a List<T>
, or really any collection that implements IEnumerable
then Rx isn't the answer. But if you have a sequence of items, some of which don't exist yet, then by all means, Rx is a good solution.