I have an object with one of its properties being an array of bytes.
I assign that property to object called obj1
. When I assign that property to a variable, it acquires the {System.Byte[]}
type which is an object, not an array.
As a result, I cannot access it. Problem is, whoever wrote the class did not define any .GetValue()
method, so I cannot really access the elements, but the debugger watch shows the values!
The only methods defined for that object are Equals
, GetType
and ToString
(which returns System.Byte
and not the values).
I have tried the following without any luck:
var vals = (System.Byte[])obj1 //Returns a {System.Byte[]} object
var vals = (obj1 as System.Byte[]) //Returns a {System.Byte[]} object
var vals = obj1.GetValue //Complains that GetValue is not defined
It is driving me crazy that I can see the array values using the watch window, but am having trouble accessing the elements.
Your first two assignments are both correct and you should be able to access the array or its elements by using
vals[0]
orvals.Length
etc