Address of array

Hi,

Could you help me to get the address of the, lets say, integer array and write it out to the console screen. How I can do it in pure C# or using .NET Framework?

Example:

public int[] a = new int[10];

...

Console.WriteLine("Address of a is ?", ?);

Thank you in advance

[324 byte] By [LieTzu] at [2007-12-22]
# 1

u can use unsafe option.

Regards,
Sudeesh

Sudeesh at 2007-8-30 > top of Msdn Tech,Visual C#,Visual C# Language...
# 2

Hi,

You can use the function "UnsafeAddrOfPinnedArrayElement"

As follows:

int[] MyArray;
MyArray = new int[5];

Console.WriteLine(Marshal.UnsafeAddrOfPinnedArrayElement(MyArray, 0));

You can iterate changin the indexer for the address of each element. The function returns a IntPtr that you can pass to unmanaged code.

Hope this helps!

SalvaPatuel at 2007-8-30 > top of Msdn Tech,Visual C#,Visual C# Language...
# 3
Don't forget to pin you object with GCHandle
MichaelNemtsev at 2007-8-30 > top of Msdn Tech,Visual C#,Visual C# Language...