delegates
multicast delegates
programming
.NET
C#

Simple Delegate delegate vs. Multicast delegates

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Delegates in C# are type-safe references to methods. The phrase "simple delegate versus multicast delegate" is really about how many methods a delegate instance points to at runtime, because the delegate type itself is declared the same way in both cases.

What a Delegate Actually Is

A delegate declaration defines a method signature that other methods must match. Once the type exists, an instance of that delegate can reference one method or several methods.

csharp
1using System;
2
3public delegate void Notifier(string message);
4
5public class Program
6{
7    static void ConsoleLog(string message)
8    {
9        Console.WriteLine($"Console: {message}");
10    }
11
12    public static void Main()
13    {
14        Notifier notify = ConsoleLog;
15        notify("hello");
16    }
17}

In this example, notify references exactly one method, so people often call it a single-cast or simple delegate. There is nothing special about the type declaration itself. The difference is in the invocation list stored inside the delegate instance.

How a Multicast Delegate Works

In C#, delegates can combine multiple handlers with +=. When you do that, the runtime keeps an invocation list and calls each method in order.

csharp
1using System;
2
3public delegate void Notifier(string message);
4
5public class Program
6{
7    static void ConsoleLog(string message)
8    {
9        Console.WriteLine($"Console: {message}");
10    }
11
12    static void AuditLog(string message)
13    {
14        Console.WriteLine($"Audit: {message}");
15    }
16
17    public static void Main()
18    {
19        Notifier notify = ConsoleLog;
20        notify += AuditLog;
21
22        notify("system started");
23    }
24}

That is a multicast delegate. It still uses the same Notifier type, but the instance now contains two method references instead of one.

This is why events in C# are so useful. They are usually backed by multicast delegates, which lets several subscribers react to the same signal.

The Important Behavioral Differences

The most obvious difference is that a single-cast delegate invokes one method, while a multicast delegate invokes several. There are also two practical consequences worth remembering.

First, if the delegate returns void, every subscribed method runs in sequence. That makes multicast delegates a natural fit for notifications.

Second, if the delegate has a return value, only the return value from the last method in the invocation list is preserved by a normal call. That often surprises people.

csharp
1using System;
2
3public delegate int Calculator(int value);
4
5public class Program
6{
7    static int AddOne(int value) => value + 1;
8    static int DoubleIt(int value) => value * 2;
9
10    public static void Main()
11    {
12        Calculator calc = AddOne;
13        calc += DoubleIt;
14
15        int result = calc(5);
16        Console.WriteLine(result); // prints 10, not 6
17    }
18}

Both methods run, but the final result comes from DoubleIt, which is last in the list.

When to Use Each Style

A single method target is fine when your code wants one callback or strategy function. A multicast invocation list is better for notifications, logging hooks, plugin callbacks, or UI-style event handling where several listeners should respond independently.

If you want subscribers to be loosely coupled, an event based on a delegate is usually cleaner than manually calling several hard-coded methods.

Common Pitfalls

  • There is no separate syntax for declaring a "multicast delegate." The same delegate type can be used in single-cast or multicast form.
  • Delegates with return values can be misleading in multicast scenarios because only the last return value is kept.
  • If one invoked method throws an exception, later handlers in the invocation list will not run unless you handle the error yourself.
  • Events are often a better public API than exposing a delegate field directly because events control subscription more safely.

Summary

  • A delegate type defines a method signature, not whether the instance is single-cast or multicast.
  • A "simple" delegate instance points to one method.
  • A multicast delegate instance stores several methods and invokes them in order.
  • Multicast delegates are especially useful for events and notifications, but be careful with return values and exceptions.

Related reading
Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.