-
Notifications
You must be signed in to change notification settings - Fork 2
/
NativeFromC#.cs
34 lines (25 loc) · 1012 Bytes
/
NativeFromC#.cs
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
30
31
32
33
34
using System.Runtime.InteropServices;
[DllImport("/native-demo/native-c#.dll")]
static extern void print_message();
[DllImport("/native-demo/native-c#.dll")]
static extern int add_numbers(int x, int y);
[DllImport("/native-demo/native-c#.dll")]
static extern int subtract_numbers(int x, int y);
[DllImport("/native-demo/native-c#.dll")]
static extern double multiply_numbers(double x, double y);
[DllImport("/native-demo/native-c#.dll")]
static extern double divide_numbers(double x, double y);
[DllImport("/native-demo/native-c#.dll")]
static extern void populate_array(double[] arrayPointer, int arraySize);
var added = add_numbers(7, 2);
var subtracted = subtract_numbers(7, 2);
var multiplied = multiply_numbers(7, 2);
var divided = divide_numbers(7, 2);
var array = new double[5];
populate_array(array, array.Length);
print_message();
Console.WriteLine(added);
Console.WriteLine(subtracted);
Console.WriteLine(multiplied);
Console.WriteLine(divided);
Console.WriteLine(string.Join(", ", array));