Use stackalloc to allocate memory for integer array : stackalloc : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » stackalloc »

 

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);
        }
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» stackalloc