Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with List<String> and Reactive extensions

I have started researching Reactive extensions and I would like to know how to do the following (ill try and keep it simple):

  1. Have a list of string (or any other type)

  2. When an item is added to the said list, do something with it.

like image 419
Stuart Blackler Avatar asked Jan 25 '26 07:01

Stuart Blackler


2 Answers

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.

like image 92
Jon Skeet Avatar answered Jan 26 '26 20:01

Jon Skeet


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!"));
like image 43
Ana Betts Avatar answered Jan 26 '26 21:01

Ana Betts