Reputation: 1649
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.
Upvotes: 10
Views: 18887
Reputation: 37533
Try
if(data.GetType().Name == "Byte[]")
{
// assign to array
}
Upvotes: 11
Reputation: 5958
How about this:
byte[] array = new byte[arrayLength];
if (array is byte[])
{
// Your code
}
Upvotes: 18
Reputation: 1649
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.
Upvotes: 1