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