緩衝區 SetByte C# 示例
SetByte() 方法將指定的值分配到指定陣列中特定位置的一個位元組。
首先,設定一個數組 −
int[] arr = { 3, 4, 12 };
現在,使用 SetByte() 來分配值 −
Buffer.SetByte(arr, 3, 20);
以下是完整的程式碼 −
示例
using System; using System.Text; public class Demo { public static void Main() { int[] arr = { 3, 4, 12 }; Console.WriteLine("Initial Array..."); // loop through the byte array for (int i = 0; i < Buffer.ByteLength(arr); i++) { Console.WriteLine(Buffer.GetByte(arr, i)); } Buffer.SetByte(arr, 3, 20); Console.WriteLine("New Array..."); // loop through the new byte array for (int i = 0; i < Buffer.ByteLength(arr); i++) { Console.WriteLine(Buffer.GetByte(arr, i)); } } }
輸出
Initial Array... 3 0 0 0 4 0 0 0 12 0 0 0 New Array... 3 0 0 20 4 0 0 0 12 0 0 0
廣告