Sep 20, 2011

Array of pointers in C#

using System;

namespace arrayDemo
{
    class Program
    {
       unsafe static void Main(string[] args)
        {
           //Array of pointer to integer.
            int*[] arr = new int*[3];

            int a = 5;
            int b = 10;
            int c = 15;

            arr[0] = &a;
            arr[1] = &b;
            arr[2] = &c;

            foreach (int* element in arr)
            {
                Console.Write("{0} ", *element);
            }
            Console.ReadKey();
        }
    }
}

5 10 15

1 comment: