-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNativeFunctions.cs
More file actions
29 lines (23 loc) 路 991 Bytes
/
Copy pathNativeFunctions.cs
File metadata and controls
29 lines (23 loc) 路 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
锘縰sing System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
public class Native
{
[UnmanagedCallersOnly(EntryPoint = "print_message")]
public static void PrintMessage() => Console.WriteLine("Hello from native code written in C#!");
[UnmanagedCallersOnly(EntryPoint = "add_numbers")]
public static int Add(int x, int y) => x + y;
[UnmanagedCallersOnly(EntryPoint = "subtract_numbers")]
public static int Subtract(int x, int y) => x - y;
[UnmanagedCallersOnly(EntryPoint = "multiply_numbers")]
public static double Multiply(double x, double y) => x * y;
[UnmanagedCallersOnly(EntryPoint = "divide_numbers")]
public static double Divide(double x, double y) => x / y;
[UnmanagedCallersOnly(EntryPoint = "populate_array")]
public static unsafe void PopulateArray(double* arrayPointer, int arraySize)
{
for (int i = 0; i < arraySize; i++)
{
arrayPointer[i] = (i * 2) + 0.5;
}
}
}