Skip to main content



C# Reactive Extensions - Buffer and Window

I was going through Buffer and Window in RX, thought a few examples would help clear the differences.

First create a buffer of even numbers, each buffer having 5 items:

(we can ignore Timestamp() for now, that will be used later when we see how buffering and windowing work with streams with items coming in over time)

int bufferId = 0; var bufferedNumberStream = Observable.Range(0, 100) .Where(v => v % 2 == 0) .Buffer(5) .Timestamp() .Subscribe(ts => { bufferId++; Console.WriteLine("Buffer ID::" + bufferId); ts.Value.ToList().ForEach(x => Console.WriteLine(x)); });
Output: Buffers created with 5 items in each buffer

Odd numbers stream with window with 5 items in each:

int windowId = 0; var windowedNumberStream = Observable.Range(0, 100) .Where(v =>; v % 2 == 1) .Timestamp() .Window(5, 5) .Subscribe(w =>; { windowId++; Console.…

Latest posts

Visitor Pattern

Double Dispatch in C#

Python: Certificate of Completion

Python: Functions - Part 1

Onwards and Upwards

Python 101 - Part 1

Passed CFA Level 2

Passed CFA Level 1

Moving a window to another monitor

Task Library: Common Patterns