Read individual bytes using GetByte() method in C# −
Set an array −
int[] arr = { 3, 4, 12 };Now, use Buffer.GetByte() to display the array elements and to read individual bytes −
for (int i = 0; i < Buffer.ByteLength(arr); i++) {
Console.WriteLine(Buffer.GetByte(arr, i));
}The following is the code −
Example
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));
}
}
}Output
3 0 0 0 4 0 0 0 12 0 0 0