What is a byte[] array?

40,530

Solution 1

In .NET, a byte is basically a number from 0 to 255 (the numbers that can be represented by eight bits).

So, a byte array is just an array of the numbers 0 - 255.

At a lower level, an array is a contiguous block of memory, and a byte array is just a representation of that memory in 8-bit chunks.

Solution 2

A byte[] array is simply an array of raw data. For example, a file of size 2000 bytes can be loaded into a byte[] array of 2000 elements.

Solution 3

Technically, all of memory is one giant array of bytes (up to 232 addressable bytes in a 32-bit address space). In C# (and C, C++, Java, and many other languages), a byte array is simply a contiguous chunk of memory. Thus a byte[n] array is a block of n bytes.

Byte arrays typically have no type other than "byte", which is simply an 8-bit data item.

Byte arrays are generally used for low-level I/O, such as read/write buffers for files and networks, as graphics image buffers, and as "untyped" data streams.

Addendum

Bytes are also known as octets, i.e., eight-bit values. Octets are the universal unit for data interchange between practically all computer and information systems in use today.

Even systems and encodings that use something other than 8-bit values still use octets to read from, write to, and transfer data between those systems. For example, audio CD sound samples are encoded as a stereo pair of signed 16-bit values sampled at 44,100 Hz. When accessed as a flat file (e.g., as a .WAV file) or data stream, though, it appears as a sequence of octets.

In the context of programming languages, then, such a sound file could be stored in its raw form as a single byte array.

Solution 4

A byte is 8 bits, and an array of byte, is an array of bytes... It really is that simple.

The thing to keep in mind is that char and byte are different. In old C style, a char and byte were basically the same thing. In .NET, characters are Unicode and can be anywhere from 8-32 bits per character. This is where encoding comes into play. You can convert a string to a byte array, and you can convert a byte array into a string by using the Encoding class.

Solution 5

It's an array of byte. It's binary data - unstructured (in terms of the language at that point in time - different than meaningless!) data which can be arbitrarily long.

Think of loading a picture from a file. You would read the file into a byte[] before working with the image.

Share:
40,530
dotnet-practitioner
Author by

dotnet-practitioner

Updated on June 29, 2020

Comments

  • dotnet-practitioner
    dotnet-practitioner about 4 years

    What is a byte array is in the context of .NET framework?

    I am familiar with standard definitions like array and byte and very familiar with electronic engineering concepts such as Byte. But I fail to connect it in terms of computer science concepts. I see it used everywhere, and I use it with out really understanding it deeply.