Skip to main content
๐Ÿ“œ 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:

  1. 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 and value >= threshold, fires Triggered with that sensor and value. Unknown sensors are ignored.
    • void Disarm(string sensor).
  2. static List<int> LevelsAbove(List<int> readings, int threshold) โ€” readings strictly above the threshold, as a lambda-filtered list.
  3. static Func<int> MakeAverager() โ€” returns a closure that yields the running average of all values passed to successive calls (first call = first value).