Monday, June 23, 2025 15:18

Posts Tagged ‘delegate chaining’

Events

Wednesday, February 5th, 2020

Events are a more secure way of implementing the observer pattern described in the previous lesson, and they are the evolutionary step of raw delegates. You may have heard about the event-driven programming as a concept that describes a programming paradigm in which the flow of the program is determined by events such as user actions (mouse clicks, key presses), sensor outputs, or messages from other programs or threads.… Read more

Observer Pattern

Monday, February 3rd, 2020

According to Microsoft, observer pattern is a behavioral design that allows one object to notify other objects about changes in its state.

Many beginner programmers (and even more experienced ones) have a hard time understanding the link between delegates and events, and the core upon which this link is built is represented precisely by the observer pattern.… Read more

Closures

Sunday, February 2nd, 2020

Let’s consider the following Action:

using System;

namespace HelloWorld
{

    public class Program
    {
        public static void Main()
        {
            int i = 0;

            Action a = () => i++;

            a();
            a();
            a();

            Console.WriteLine(i);

            Console.Read();
        }
    }
}

From the lesson Func and Action, you remember that an Action is just a delegate that returns void and takes between 0 and 16 parameters of any type.… Read more

Delegate chaining

Friday, January 24th, 2020

An useful property of delegate objects is that multiple objects can be assigned to one delegate instance using the + operator, process called delegate chaining.

Delegate chaining isn’t really useful until we will get to events and event subscribers, which will come in a future lesson, but it’s better to describe the behavior now, after you’ve seen a bit of delegates inner workings.… Read more