Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty elements in C# byte array

Tags:

arrays

c#

byte

Is there any method to empty an Byte array in C#?

Byte[] array = new Byte[64]; // contain all 0  // write some value into the array  // need empty array with all 0's 
like image 437
leon22 Avatar asked Jul 01 '11 09:07

leon22


People also ask

What is an empty array in C?

There's no such thing as an "empty array" or an "empty element" in C. The array always holds a fixed pre-determined number of elements and each element always holds some value. The only way to introduce the concept of an "empty" element is to implement it yourself.

Can I declare an empty array in C?

Technically you can't make an array empty. An array will have a fixed size that you can not change. If you want to reset the values in the array, either copy from another array with default values, or loop over the array and reset each value.

What is the value of an empty array in C?

//there is no "empty" in C. There is always a fixed number of elements with some value.

What is null in C?

The C and C++ languages have a null character (NUL), a null pointer (NULL), and a null statement (just a semicolon (;)). The C NUL is a single character that compares equal to 0. The C NULL is a special reserved pointer value that does not point to any valid data object.


2 Answers

Byte[] array = new Byte[64];  Array.Clear(array, 0, array.Length); 
like image 106
Petar Ivanov Avatar answered Sep 19 '22 18:09

Petar Ivanov


Kindly use Array.Empty method

byte[] rawBytes = Array.Empty();

like image 29
Mak Ahmed Avatar answered Sep 20 '22 18:09

Mak Ahmed