I'm trying to use the Read function, and I was wondering if it is possible to pass in and cast one of my own objects to a byte [] and read it into that structure directly.


Basically I have a class with some properties, I initialize it and what not then I want to read it's contents from a binary file using the read function.

So basically my class has some ints longs doubkes etc...all public

then I want to

file.Read((byte[])myclass, (int)file.BaseStream.Position, (int)Marshal.SizeOf(myclass));

but the cast from myclass to byte[] fails.