CKTIS / C#
delegate: referência prática
delegate: referência prática: delegate declara um tipo de assinatura invocável ou cria uma função anónima.
Versão: C# language and .NET 10 reference runtime
Sintaxe
delegate /* grammar-specific form */delegate declara um tipo de assinatura invocável ou cria uma função anónima.
Usa-o para callbacks, estratégias e eventos com contrato de parâmetros controlado.
Um multicast delegate devolve o resultado do último handler e uma exceção para chamadas posteriores.
Um delegate pode ser null; variance aplica-se apenas a tipos referência compatíveis.
O programa completo usa realmente delegate; o stdout exato esperado é 8.
Exemplos
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
O programa completo usa realmente `delegate`; o stdout exato esperado é `8`.