← Back to C# Course | Chapter 12: Delegates & Events | Lesson 1 of 6

Delegates

In this page:

  1. Delegates

Delegates

A delegate is a type-safe reference to a method, letting you pass methods around as values — as parameters, return values, or stored in variables. You declare a delegate type describing the method signature it can point to, then assign any matching method to it. Calling the delegate invokes whichever method it currently references.

Note: Delegates are the foundation that lambda expressions, Func<>/Action<>, and events are all built on.

Example: Delegates

markup
using System;

delegate int Operation(int a, int b);

class Program
{
    static int Add(int a, int b) => a + b;
    static int Multiply(int a, int b) => a * b;

    static void Main(string[] args)
    {
        Operation op = Add;
        Console.WriteLine(op(3, 4));

        op = Multiply;
        Console.WriteLine(op(3, 4));
    }
}
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.