I'm not entirely sure that this is what you're looking for, but one example would be like this:
int[] items = new int[10];
unsafe
{
fixed ( int* pInt = &items[0] )
{
// At this point you can pass the pointer to other functions
// or read/write memory using it.
*pInt = 5;
}
}
When taking the address of an array, you have to take the address of the first item in the array - hence &items[0] in the example above.
If you receive the pointer as a void* function parameter, you have to cast it inside the function:
public static unsafe void F ( void* pMem )
{
int* pInt = (int*) pMem;
// Omitted checking the pointer here, etc. This is something
// you'd have to do in a real program.
*pInt = 1;
}
If you receive a void* from an external source, you'll have to somehow know how many bytes (or ints, etc.) are safe to access through the pointer. The data may be delimited by a special value (like a terminating 0 or something else) or you'd need a count or bytes / elements to safely access memory through the pointer.
Update
Here's an example of calling an unmanaged function implemented in C:
// Function declaration in C
#define EXPORTFUNC __declspec(dllexport)
#define MYDLLAPI __declspec(nothrow) WINAPI
EXPORTFUNC int MYDLLAPI MyFunc1 ( byte* pData, int nDataByteCount );
// Import function in C#
[DllImport ( "My.dll" )]
private static extern int MyFunc1 ( byte* pData, int nDataByteCount );
// Call function with data (in unsafe class / method)
byte[] byData = GetData ( ... ); // returns byte array with data
fixed ( byte* pData = byData )
{
int nResult = MyFunc1 ( pData, byData.Length );
...
}
MSDN has more examples on various pointer operations. Also, here's another article about marshaling arrays.
int*or you have to receive it as such. If you receive avoid*, you'll have to cast it to be able to use it.