Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / C#

delegate: referencia práctica

delegate: referencia práctica: delegate declara un tipo de firma invocable o crea una función anónima.

Versión: C# language and .NET 10 reference runtime

Sintaxis

delegate /* grammar-specific form */

delegate declara un tipo de firma invocable o crea una función anónima.

Úsalo para callbacks, estrategias y eventos con contrato de parámetros controlado.

Un multicast delegate devuelve el resultado del último handler y una excepción detiene llamadas posteriores.

Un delegate puede ser null; variance solo aplica a tipos de referencia compatibles.

El programa completo usa realmente delegate; su stdout esperado exacto es 8.

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;

Transformer transform = value => value * 2; Console.WriteLine(transform(4));
delegate int Transformer(int value);

Resultado

8

El programa completo usa realmente `delegate`; su stdout esperado exacto es `8`.

Fuentes