/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/csharp/language-reference/snippets/unsafe-code/FunctionPointers.cs
44 строки
2 KB
Bill Wagner
Use Collection expressions for all language reference samples (#37993)
16 ноя 2023, 23:06
Не верифицирован
16 ноя 2023, 23:06
ace7aec
Код
Авторство
О чём код?
namespace UnsafeCodePointers; public unsafe class FunctionPointers { public static void PointerExamples() { int sum = Combine((x, y) => x + y, 3, 4); Console.WriteLine(sum); Console.WriteLine(); // <InvokeViaFunctionPointer> static int localMultiply(int x, int y) => x * y; int product = UnsafeCombine(&localMultiply, 3, 4); // </InvokeViaFunctionPointer> Console.WriteLine(product); } // <UseDelegateOrPointer> public static T Combine<T>(Func<T, T, T> combinator, T left, T right) => combinator(left, right); public static T UnsafeCombine<T>(delegate*<T, T, T> combinator, T left, T right) => combinator(left, right); // </UseDelegateOrPointer> // <UnmanagedFunctionPointers> public static T ManagedCombine<T>(delegate* managed<T, T, T> combinator, T left, T right) => combinator(left, right); public static T CDeclCombine<T>(delegate* unmanaged[Cdecl]<T, T, T> combinator, T left, T right) => combinator(left, right); public static T StdcallCombine<T>(delegate* unmanaged[Stdcall]<T, T, T> combinator, T left, T right) => combinator(left, right); public static T FastcallCombine<T>(delegate* unmanaged[Fastcall]<T, T, T> combinator, T left, T right) => combinator(left, right); public static T ThiscallCombine<T>(delegate* unmanaged[Thiscall]<T, T, T> combinator, T left, T right) => combinator(left, right); public static T UnmanagedCombine<T>(delegate* unmanaged<T, T, T> combinator, T left, T right) => combinator(left, right); // </UnmanagedFunctionPointers> }