๐ WAYPOINT LESSON
Checkpoint โ Delegates & events
โญ beginnerโณ 20 min read๐ Lesson 65 of 85
An alarm system: sensors publish, a panel subscribes, filters are lambdas, and history is a closure.
Checkpoint: the alarm system
Task: implement in Solution:
- Nested class
AlarmSystem:event Action<string, int>? Triggered;(sensor name, level)void Arm(string sensor, int threshold)โ records the sensor's threshold.void Reading(string sensor, int value)โ when the sensor is armed andvalue >= threshold, firesTriggeredwith that sensor and value. Unknown sensors are ignored.void Disarm(string sensor).
static List<int> LevelsAbove(List<int> readings, int threshold)โ readings strictly above the threshold, as a lambda-filtered list.static Func<int> MakeAverager()โ returns a closure that yields the running average of all values passed to successive calls (first call = first value).