How to check if an object contains an array of bytes?

I am having a problem with the following code.

byte[] array = data as byte[]; // compile error - unable to use built-in conversion if (array != null) { ... 

I only want to assign the data to an array variable if the data is actually a byte array.

+6
arrays c #
source share
3 answers

Try

 if(data.GetType().Name == "Byte[]") { // assign to array } 
+6
source share

How about this:

 byte[] array = new byte[arrayLength]; if (array is byte[]) { // Your code } 
+8
source share

As soon as I asked about this, I realized that the data type is not an object.

Creating this type object (entering it through a type converter in Silverlight), and it worked.

+1
source share

All Articles