这可能是一个真正的开瓶器的问题,但我一直在阅读关于这一点,我觉得很难理解。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
我不明白这是如何工作,有人可以给我一些有关此信息?