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 datastream, publish data to that stream, and subscribe to it.

Get C# 7 and .NET Core 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.