I need to process a binary resource (contents of a binary file). The file contains shorts. I can't figure how to cast the result of accessing that resource to a short array though:
short[] indexTable = Properties.Resources.IndexTable;
doesn't work; I can only use
byte[] indexTable = Properties.Resources.IndexTable;
Using Array.Copy wouldn't work since it would convert each byte from the array returned by accessing the resource to a short.
How do I solve this problem please (other than manually converting the byte array)? Is there a way to tell C# that the resource is of type short[] rather than byte[]?
I had even tried to edit the project's resx file and change the resources' data types to System.UInt16, but then I got the error message that now constructor could be found for them.
Using VS 2010 Express and .NET 4.0.
You should use BinaryReader:
using (var reader = new BinaryReader(new MemoryStream(Properties.Resources.IndexTable)))
{
var firstValue = reader.ReadInt16();
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With