Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

delegate: practical reference

delegate: practical reference: delegate declares a callable signature type or creates an anonymous function.

Version: C# language and .NET 10 reference runtime

Syntax

delegate /* grammar-specific form */

delegate declares a callable signature type or creates an anonymous function.

Use it for callbacks, strategies, and events with a controlled parameter contract.

A multicast delegate returns the last handler result, and an exception stops later calls.

A delegate can be null; variance applies only to compatible reference types.

The complete program actually uses delegate; its exact expected stdout is 8.

Examples

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);

Result

8

The complete program actually uses `delegate`; its exact expected stdout is `8`.

Sources