C# 中的 Buffer GetByte 示例
在 C# 中使用 GetByte() 方法讀取各個位元組 -
設定一個數組 -
int[] arr = { 3, 4, 12 };
現在,使用 Buffer.GetByte() 顯示陣列元素並讀取各個位元組 -
for (int i = 0; i < Buffer.ByteLength(arr); i++) { Console.WriteLine(Buffer.GetByte(arr, i)); }
以下為程式碼 -
示例
using System; using System.Text; public class Demo { public static void Main() { int[] arr = { 3, 4, 12 }; // loop through the byte array for (int i = 0; i < Buffer.ByteLength(arr); i++) { Console.WriteLine(Buffer.GetByte(arr, i)); } } }
輸出
3 0 0 0 4 0 0 0 12 0 0 0
廣告