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 ...

Get C# Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.