tags:

views:

51

answers:

3

I'm having an issue 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 array variable if the data is actually a byte array.

A: 

Try

if(data.GetType().Name == "I forget what the exact name is for a byte array") 
{
    // assign to array
}
Joel Etherton
"Byte[]" Yep that would work too. fixed my problem by checking the type of an object.
Stephen Price
+1  A: 

As soon as I asked this I realised that the type of data was not object.

Making it of type object (its coming in via a type converter in Silverlight) and it worked.

Stephen Price
A: 

How about this:

byte[] array = new  byte[arrayLength];
if (array is byte[])
{
    // Your code
}
Upul