diff --git a/docs/csharp/language-reference/snippets/unsafe-code/FunctionPointers.cs b/docs/csharp/language-reference/snippets/unsafe-code/FunctionPointers.cs
index 760730c1807bc..b9bb8b16b349e 100644
--- a/docs/csharp/language-reference/snippets/unsafe-code/FunctionPointers.cs
+++ b/docs/csharp/language-reference/snippets/unsafe-code/FunctionPointers.cs
@@ -1,6 +1,6 @@
namespace UnsafeCodePointers;
-public unsafe class FunctionPointers
+public class FunctionPointers
{
public static void PointerExamples()
{
@@ -10,35 +10,36 @@ public static void PointerExamples()
Console.WriteLine();
//
- static int localMultiply(int x, int y) => x * y;
- int product = UnsafeCombine(&localMultiply, 3, 4);
+ int product = 0;
+ unsafe
+ {
+ static int localMultiply(int x, int y) => x * y;
+ product = UnsafeCombine(&localMultiply, 3, 4);
+ }
//
Console.WriteLine(product);
-
-
}
//
public static T Combine(Func combinator, T left, T right) =>
combinator(left, right);
- public static T UnsafeCombine(delegate* combinator, T left, T right) =>
+ public static unsafe T UnsafeCombine(delegate* combinator, T left, T right) =>
combinator(left, right);
//
//
- public static T ManagedCombine(delegate* managed combinator, T left, T right) =>
+ public static unsafe T ManagedCombine(delegate* managed combinator, T left, T right) =>
combinator(left, right);
- public static T CDeclCombine(delegate* unmanaged[Cdecl] combinator, T left, T right) =>
+ public static unsafe T CDeclCombine(delegate* unmanaged[Cdecl] combinator, T left, T right) =>
combinator(left, right);
- public static T StdcallCombine(delegate* unmanaged[Stdcall] combinator, T left, T right) =>
+ public static unsafe T StdcallCombine(delegate* unmanaged[Stdcall] combinator, T left, T right) =>
combinator(left, right);
- public static T FastcallCombine(delegate* unmanaged[Fastcall] combinator, T left, T right) =>
+ public static unsafe T FastcallCombine(delegate* unmanaged[Fastcall] combinator, T left, T right) =>
combinator(left, right);
- public static T ThiscallCombine(delegate* unmanaged[Thiscall] combinator, T left, T right) =>
+ public static unsafe T ThiscallCombine(delegate* unmanaged[Thiscall] combinator, T left, T right) =>
combinator(left, right);
- public static T UnmanagedCombine(delegate* unmanaged combinator, T left, T right) =>
+ public static unsafe T UnmanagedCombine(delegate* unmanaged combinator, T left, T right) =>
combinator(left, right);
//
-
}