這可能是一個真正的開瓶器的問題,但我一直在閱讀關於這一點,我覺得很難理解。c#緩衝區說明
這是關於此主題的msdn頁面的示例(只是略小一些)。
using System;
class SetByteDemo
{
// Display the array contents in hexadecimal.
public static void DisplayArray(Array arr, string name)
{
// Get the array element width; format the formatting string.
int elemWidth = Buffer.ByteLength(arr)/arr.Length;
string format = String.Format(" {{0:X{0}}}", 2 * elemWidth);
// Display the array elements from right to left.
Console.Write("{0,7}:", name);
for (int loopX = arr.Length - 1; loopX >= 0; loopX--)
Console.Write(format, arr.GetValue(loopX));
Console.WriteLine();
}
public static void Main()
{
// These are the arrays to be modified with SetByte.
short[] shorts = new short[2];
Console.WriteLine("Initial values of arrays:\n");
// Display the initial values of the arrays.
DisplayArray(shorts, "shorts");
// Copy two regions of source array to destination array,
// and two overlapped copies from source to source.
Console.WriteLine("\n" +
" Array values after setting byte 1 = 1 and byte 3 = 200\n");
Buffer.SetByte(shorts, 1, 1);
Buffer.SetByte(shorts, 3, 10);
// Display the arrays again.
DisplayArray(shorts, "shorts");
Console.ReadKey();
}
}
SetByte
應該很容易理解,但如果我做SetByte
操作數組看起來像這樣
{short[2]}
[0]: 0
[1]: 0
做第一Buffer.SetByte(shorts, 1, 1);
後陣之前打印短褲陣列變得
{short[2]}
[0]: 256
[1]: 0
並且在設置Buffer.SetByte(shorts, 3, 10);
之後,陣列變爲
{short[2]}
[0]: 256
[1]: 2560
最後,在本例中,他們打印陣列由右至左:
0A00 0100
我不明白這是如何工作,有人可以給我一些有關此信息?