How to find out is bytes array has any data or it is newly created bytes array?
var Buffer = new byte[1000];
//How to find out is Buffer is empty or not?
How to find out is bytes array has any data or it is newly created bytes array?
var Buffer = new byte[1000];
//How to find out is Buffer is empty or not?
I assume by 'empty' you mean containing default values for every byte element, if this isn't what you mean, look at @sehe's answer.
How about using LINQ to check whether all elements have the default value for the type:
var Empty = Buffer.All(B => B == default(Byte));
default(T) would only have a meaning in the context of a template, IIRC.All() method on System.Buffer does not exist. Even if I include System.Linq.A byte is a valuetype, it cannot be null;
Creating an array immediately initializes the elements to the default value for the element type.
This means, empty cells can't exist, let alone be detected.
If you must:
use nullable types
var Buffer = new byte?[1000];
use Array.Resize when capacity changes. However, you could soon be in a situation where just using a System.Collections.Generic.List would be much more efficient