CKTIS / C#
delegates and events: referencia práctica
delegates and events: referencia práctica: Un delegado guarda un contrato invocable y un event limita al propietario la publicación de suscriptores.
Versión: C# language and .NET 10 reference runtime
Sintaxis
// delegates eventsUn delegado guarda un contrato invocable y un event limita al propietario la publicación de suscriptores.
Usa callbacks y eventos para notificaciones desacopladas con ciclo de vida explícito.
Una suscripción mantiene una referencia al receptor; omitir unsubscribe puede provocar una fuga.
La excepción de un handler interrumpe una invocación multicast normal.
El programa completo usa realmente delegates and events; su stdout esperado exacto es 5.
Ejemplos
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
var source = new Source(); source.Changed += value => Console.WriteLine(value); source.Raise(5); sealed class Source { public event Action<int>? Changed; public void Raise(int value) => Changed?.Invoke(value); }
Resultado
5
El programa completo usa realmente `delegates and events`; su stdout esperado exacto es `5`.