Created
April 10, 2016 11:51
-
-
Save semuserable/f41b3d848f1b57f82e18b70c309678e6 to your computer and use it in GitHub Desktop.
Rx .NET samples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main() | |
{ | |
IObservable<int> observable = Enumerable.Range(0, 10).ToObservable(); | |
// Long version | |
observable.Subscribe(new IntObserver()); | |
// Short version (lambda) | |
observable.Subscribe(Console.WriteLine) | |
// Short version (method) | |
observable.Subscribe(OnNextInt); | |
} | |
static void OnNextInt(int value) | |
{ | |
Console.WriteLine(value) | |
} | |
class IntObserver : IObserver<int> | |
{ | |
public void OnNext(int value) | |
{ | |
Console.WriteLine(value); | |
} | |
public void OnError(Exception error) | |
{ | |
Console.WriteLine("OnError"); | |
} | |
public void OnCompleted() | |
{ | |
Console.WriteLine("OnCompleted"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment