📌 Introduction

Events are a core concept in C# that enable different parts of an application to communicate cleanly and loosely coupled.

Instead of one class directly calling methods on another, it can simply raise an event and let interested components respond.

In this article, we will understand C# events using a very simple real-life example:
A patient entering an ICU and hospital staff being notified.

Note: This ICU room example is used purely to explain the concept of events in a simple and relatable way. It is not intended to represent real-world medical systems or production-level healthcare software.

No frameworks. No advanced patterns. Just clear fundamentals.

❓ What Is an Event in C#?

An event is a mechanism that allows a class to notify other classes when an event occurs.

In simple terms:

This makes the code easier to maintain and extend.

🏥 Real-Life Scenario: ICU Room

When a patient enters the ICU:

Important Point

💻 Simple Example Code

// Delegate defines what methods can handle the event
public delegate void ICURoom();

public class Program
{
    // Event declaration
    public event ICURoom? InformStaffAboutPatientHasEnteredInICU;

    // Event subscribers
    public void InformDoctor()
    {
        Console.WriteLine("Informing Doctor About The Patient");
    }

    public void InformNurse()
    {
        Console.WriteLine("Informing Nurses About The Patient");
    }

    // Method that raises the event
    public void PatientEnteredInICU()
    {
        Console.WriteLine("Patient has entered the ICU");
        InformStaffAboutPatientHasEnteredInICU?.Invoke();
    }

    static void Main(string[] args)
    {
        Program program = new Program();

        // Subscribing to the event
        program.InformStaffAboutPatientHasEnteredInICU += program.InformDoctor;
        program.InformStaffAboutPatientHasEnteredInICU += program.InformNurse;

        // Triggering the event
        program.PatientEnteredInICU();

        Console.ReadLine();
    }
}

🧩 Step-by-Step Explanation

1️⃣ Delegate

public delegate void ICURoom();

The delegate defines the method signature that can respond to the event.

2️⃣ Event Declaration

public event ICURoom? InformStaffAboutPatientHasEnteredInICU;

This event represents:
"A patient has entered the ICU."

3️⃣ Subscribing to the Event

program.InformStaffAboutPatientHasEnteredInICU += program.InformDoctor;
program.InformStaffAboutPatientHasEnteredInICU += program.InformNurse;

4️⃣ Raising the Event

InformStaffAboutPatientHasEnteredInICU?.Invoke();

📤 Output

Patient has entered the ICU
Informing Doctor About The Patient
Informing Nurses About The Patient

🤔 Why Use Events Here?

This is exactly what events are designed for.

🎯 Simple Interview Explanation

Events allow one class to notify multiple other classes about an action without knowing who those classes are.

Clear, short, and effective.

🧠 Conclusion

This simple ICU example demonstrates how events work in C# at a fundamental level.

The same concept is used in real applications such as:

Once this foundation is clear, learning advanced event patterns becomes much easier.

🙏 Thank You

Thank you for reading this article.

I hope this simple ICU example helped you understand events in C# clearly.

Feel free to share your feedback or questions in the comments section.