Repository navigation
KO CSharp Keyword managed function pointer calling convention
Codex edited this page Oct 11, 2026
·
2 revisions
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Delegate* 유형에서 관리되는 것은 관리되는 통화 계약을 지정합니다. 이는 기본 옵션이기도 합니다. 주소는 정적 메서드의 & 연산자로 가져옵니다. 포인터 선언 및 호출은 안전하지 않은 컨텍스트에서 실행됩니다. 프로젝트는 안전하지 않은 블록을 허용해야 합니다. 함수 포인터는 대리자 개체가 아닙니다.
이 예제를 Example.cs로 따로 저장하고 이 페이지의 다른 예제와 독립적으로 실행하세요.
Example.cs:
// PROJECT-EXAMPLE
unsafe
{
delegate* managed<int, int> twice = &Twice;
System.Console.WriteLine(twice(4));
}
static int Twice(int value) => value * 2;프로젝트에서 <AllowUnsafeBlocks>true</AllowUnsafeBlocks>를 활성화하세요. 포인터는 표시된 범위 내에서만 유효합니다.
결과:
8
delegate* managed<int, int> operation = &Transform;파일 Example.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>14.0</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
</Project>파일 Program.cs:
using System;
internal static unsafe class Program
{
public static void Main()
{
delegate* managed<int, int> square = □
Console.WriteLine(square(7));
}
private static int Square(int value) => value * value;
}결과:
49
파일 Example.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>14.0</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
</Project>파일 Program.cs:
using System;
internal static unsafe class Program
{
public static void Main()
{
delegate* managed<int, int, int> combine = &Add;
Console.WriteLine(Apply(combine, 8, 3));
combine = &Subtract;
Console.WriteLine(Apply(combine, 8, 3));
}
private static int Apply(delegate* managed<int, int, int> operation, int left, int right)
=> operation(left, right);
private static int Add(int left, int right) => left + right;
private static int Subtract(int left, int right) => left - right;
}결과:
11
5
공식 출처: Microsoft 학습.
ClassicUO — Bad Newbie & C# Scripts IDE