Use stackalloc to allocate memory for integer array
using System;
class TestStackallocApp
{
unsafe public static void Foo(int* pa)
{
for (int* ip = pa; ip < (pa+5); ip++)
{
Console.WriteLine("value {0} at address: {1}", *ip, (int)ip);
}
}
static void Main(string[] args)
{
unsafe
{
int* pa = stackalloc int[5];
pa[0] = 12;
pa[1] = 34;
pa[2] = 56;
pa[3] = 78;
pa[4] = 90;
Foo(pa);
}
}
}
Related examples in the same category