Skip to main content

Practice · 2 of 2

TelemetrySource: Custom EventArgs and Unsubscribe

CHALLENGE
Difficulty: intermediate+25 XP

Implement TelemetrySource with a custom args record and honest lifecycle: Emit raises Reading for current subscribers with the channel and value; SubscriberCount reflects += and -= truthfully; a handler that unsubscribed stops receiving (but other subscribers keep working). ``csharp public sealed record ReadingEventArgs(string Channel, double Value); public class TelemetrySource { public event EventHandler<ReadingEventArgs>? Reading; public void Emit(string channel, double value); public int SubscriberCount { get; } } ``

Back to lesson: Practice: Events Practice: Publish, Subscribe, Unsubscribe