simple question, I import a DLL function and the parameter are int*. When I try to enter Method(0), I get an error which says: \"int and int* can not convert\".
What
That is classic C notation for a pointer to an int. Whenever a type is followed by a *, it denotes that type as a pointer to that type. In C#, unlike in C, you must explicitly define functions as unsafe to use pointers, in addition to enabling unsafe code in your project properties. A pointer type is also not directly interchangeable with a concrete type, so the reference of a type must be taken first. To get a pointer to another type, such as an int, in C# (or C & C++ for that matter), you must use the dereference operator & (ampersand) in front of the variable you wish to get a pointer to:
unsafe
{
int i = 5;
int* p = &i;
// Invoke with pointer to i
Method(p);
}
'Unsafe' code C#
Below are some key articles on unsafe code and the use of pointers in C#.