CKTIS / C#
delegate: odniesienie praktyczne
delegate: odniesienie praktyczne: delegate deklaruje typ wywoływalnej sygnatury lub tworzy funkcję anonimową.
Wersja: C# language and .NET 10 reference runtime
Składnia
delegate /* grammar-specific form */delegate deklaruje typ wywoływalnej sygnatury lub tworzy funkcję anonimową.
Stosuj do callbacków, strategii i eventów z kontrolowanym kontraktem parametrów.
Multicast zwraca wynik ostatniego handlera, a wyjątek przerywa dalsze wywołania.
Delegat może być null; variance działa tylko dla zgodnych typów referencyjnych.
Kompletny program rzeczywiście używa delegate; oczekiwany stdout to dokładnie 8.
Przykłady
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);
Wynik
8
Kompletny program rzeczywiście używa `delegate`; oczekiwany stdout to dokładnie `8`.