C# program to count number of bytes in an array

CsharpProgrammingServer Side Programming

Set a byte array −

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

To count number of bytes −

Buffer.ByteLength(b)

The following is the code −

Example

 Live Demo

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);
   }
}

Output

5
9
19
23
29
35
55
78
Length of byte array = 8
raja
Published on 04-Sep-2018 11:22:44
Advertisements