Events versus observables
Being developers, we should all be quite familiar with events. Most developers have been creating events since we started writing code. In fact, if you have even dropped a button control on a form and double-clicked the button to create the method that handles the click of the button, you have created an event. In .NET, we can declare events using the event
keyword, publish to the event by invoking it, and subscribe to that event by adding a handler to the event. We therefore have the following operations:
- Declare
- Publish
- Subscribe
With Rx, we have a similar structure where we declare a data stream, publish data to that stream, and subscribe to it.
Getting ready
First, we will see how an event works in C#. We will then see the working of an event using Rx and, in doing so, highlight the differences.
How to do it…
- In your console application, add a new class called
DotNet
. To this class, add a property calledAvailableDatatype
:public class DotNet { public string...