2012-10-31 13 views

回答

1

以下內容適用於unsafe環境。

fixed (int* baseOffset = values) 
{ 
    var offset = baseOffset; 
    var count = len1 * len2; 
    for (int i = 0; i < count; i++) 
    { 
     int value = *offset; 
     // Do whatever you need to do here 
     offset++; 
    } 
} 

請注意,要獲取指向數組中第一項的指針,類型必須匹配。所以如果你有一個byte*你想把它當作ushort*,你不能在fixed語句的圓括號內強制轉換指針,儘管你可以在塊中做到這一點。