1
1
namespace UnsafeCodePointers ;
2
2
3
- public unsafe class FunctionPointers
3
+ public class FunctionPointers
4
4
{
5
5
public static void PointerExamples ( )
6
6
{
@@ -10,35 +10,36 @@ public static void PointerExamples()
10
10
Console . WriteLine ( ) ;
11
11
12
12
// <InvokeViaFunctionPointer>
13
- static int localMultiply ( int x , int y ) => x * y ;
14
- int product = UnsafeCombine ( & localMultiply , 3 , 4 ) ;
13
+ int product = 0 ;
14
+ unsafe
15
+ {
16
+ static int localMultiply ( int x , int y ) => x * y ;
17
+ product = UnsafeCombine ( & localMultiply , 3 , 4 ) ;
18
+ }
15
19
// </InvokeViaFunctionPointer>
16
20
Console . WriteLine ( product ) ;
17
-
18
-
19
21
}
20
22
21
23
// <UseDelegateOrPointer>
22
24
public static T Combine < T > ( Func < T , T , T > combinator , T left , T right ) =>
23
25
combinator ( left , right ) ;
24
26
25
- public static T UnsafeCombine < T > ( delegate * < T , T , T > combinator , T left , T right ) =>
27
+ public static unsafe T UnsafeCombine < T > ( delegate * < T , T , T > combinator , T left , T right ) =>
26
28
combinator ( left , right ) ;
27
29
// </UseDelegateOrPointer>
28
30
29
31
// <UnmanagedFunctionPointers>
30
- public static T ManagedCombine < T > ( delegate * managed< T , T , T > combinator , T left , T right ) =>
32
+ public static unsafe T ManagedCombine < T > ( delegate * managed< T , T , T > combinator , T left , T right ) =>
31
33
combinator ( left , right ) ;
32
- public static T CDeclCombine < T > ( delegate * unmanaged[ Cdecl] < T , T , T > combinator , T left , T right ) =>
34
+ public static unsafe T CDeclCombine < T > ( delegate * unmanaged[ Cdecl] < T , T , T > combinator , T left , T right ) =>
33
35
combinator ( left , right ) ;
34
- public static T StdcallCombine < T > ( delegate * unmanaged[ Stdcall] < T , T , T > combinator , T left , T right ) =>
36
+ public static unsafe T StdcallCombine < T > ( delegate * unmanaged[ Stdcall] < T , T , T > combinator , T left , T right ) =>
35
37
combinator ( left , right ) ;
36
- public static T FastcallCombine < T > ( delegate * unmanaged[ Fastcall] < T , T , T > combinator , T left , T right ) =>
38
+ public static unsafe T FastcallCombine < T > ( delegate * unmanaged[ Fastcall] < T , T , T > combinator , T left , T right ) =>
37
39
combinator ( left , right ) ;
38
- public static T ThiscallCombine < T > ( delegate * unmanaged[ Thiscall] < T , T , T > combinator , T left , T right ) =>
40
+ public static unsafe T ThiscallCombine < T > ( delegate * unmanaged[ Thiscall] < T , T , T > combinator , T left , T right ) =>
39
41
combinator ( left , right ) ;
40
- public static T UnmanagedCombine < T > ( delegate * unmanaged< T , T , T > combinator , T left , T right ) =>
42
+ public static unsafe T UnmanagedCombine < T > ( delegate * unmanaged< T , T , T > combinator , T left , T right ) =>
41
43
combinator ( left , right ) ;
42
44
// </UnmanagedFunctionPointers>
43
-
44
45
}
0 commit comments