迭代一個陣列

int[] arr = new int[] {1, 6, 3, 3, 9};

for (int i = 0; i < arr.Length; i++) 
{
    Console.WriteLine(arr[i]);
}

使用 foreach:

foreach (int element in arr) 
{
    Console.WriteLine(element);
}

使用指標進行不安全訪問 https://msdn.microsoft.com/en-ca/library/y31yhkeb.aspx

unsafe
{
    int length = arr.Length;
    fixed (int* p = arr)
    {
        int* pInt = p;
        while (length-- > 0)
        {
            Console.WriteLine(*pInt);
            pInt++;// move pointer to next element
        }
    }
}

輸出:

1
6
3
3
9