Computer >> 컴퓨터 >  >> 프로그램 작성 >> C#

배열의 바이트 수를 계산하는 C# 프로그램

<시간/>

바이트 배열 설정 -

byte[] b = { 5, 9, 19, 23, 29, 35, 55, 78 };

바이트 수를 계산하려면 -

Buffer.ByteLength(b)

다음은 코드입니다 -

예시

using System;
class Program {
   static void Main() {
      byte[] b = { 5, 9, 19, 23, 29, 35, 55, 78 };
      int len = Buffer.ByteLength(b);
      for (int i = 0; i < len; i++) {
         Console.WriteLine(b[i]);
      }
      Console.WriteLine("Length of byte array = "+len);
   }
}

출력

5
9
19
23
29
35
55
78
Length of byte array = 8