using System; using System.Collections.Generic; public interface IMarketData { string Name { get; } decimal Price { get; } } public class Stock : IMarketData, IObservableIn this example, the Stock class implements the IObservable interface and keeps a list of observers. The AbcStockObserver class is an observer that subscribes to changes in the stock market and reacts only to changes in the ABC stock. The Unsubscriber class is responsible for removing observers that no longer wish to be notified of changes. The IObserver interface is a part of the Reactive Extensions (Rx) library, which provides advanced features for working with asynchronous data streams.{ private decimal price; private List > observers = new List >(); public Stock(string name, decimal price) { this.Name = name; this.price = price; } public string Name { get; } public decimal Price { get => price; set { if (price != value) { price = value; Notify(); } } } public IDisposable Subscribe(IObserver observer) { if (!observers.Contains(observer)) { observers.Add(observer); } return new Unsubscriber(observers, observer); } private void Notify() { foreach (var observer in observers) { observer.OnNext(this); } } } public class AbcStockObserver : IObserver { public void OnCompleted() { Console.WriteLine("Done"); } public void OnError(Exception error) { Console.WriteLine($"Error: {error.Message}"); } public void OnNext(IMarketData value) { if (value.Name == "ABC") { Console.WriteLine($"Price of ABC stock has changed: {value.Price}"); } } } public class Unsubscriber : IDisposable { private List > observers; private IObserver observer; public Unsubscriber(List > observers, IObserver observer) { this.observers = observers; this.observer = observer; } public void Dispose() { if (observer != null && observers.Contains(observer)) { observers.Remove(observer); } } }