1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class Default
{
    public static void Main(string[] args)
    {
        var messageSubject = new Subject<string>();
        var consumer = new ConsoleConsumer(messageSubject);
        var producer = new StringProducer(messageSubject);
        
        producer.SendMessage("Hello world!");

        consumer.Dispose();
    }
}

public class ConsoleConsumer : IDisposable
{
    private readonly IDisposable messageSourceSubscription;

    public ConsoleConsumer(IObservable<string> messageSource)
    {
        // insert null check here
        this.messageSourceSubscription = messageSource.Subscribe(this.DisplayMessage);
    }

    public void DisplayMessage(string message)
    {
        Console.WriteLine(message);
    }

    public void Dispose()
    {
        this.messageSourceSubscription.Dispose();
    }
}

public class StringProducer
{
    private readonly IObserver<string> messageChannel;

    public StringProducer(IObserver<string> messageChannel)
    {
        // insert null check here
        this.messageChannel = messageChannel;
    }

    public void SendMessage(string message)
    {
        this.messageChannel.OnNext(message);
    }
}
Line 10 : The type or namespace name 'Subject' could not be found (are you missing a using directive or an assembly reference?)
Line 27 : The best overloaded method match for 'System.IObservable<string>.Subscribe(System.IObserver<string>)' has some invalid arguments
Line 27 : Argument 1: cannot convert from 'method group' to 'System.IObserver<string>'