使用GetByte()C#中的方法读取单个字节-
设置一个数组-
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 };
//遍历字节数组
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