Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

"Polymorphic array"

$
0
0

Assume I have an array of bytes (C#): byte[] bytes = new byte[100];
I want to expose part of the array for access and found IList/ArraySegment<byte> to be quite convenient, e.g:
IList<byte> byteList = new ArraySegment<byte>(bytes, 10, 10);
This works fine, changing a byte in the byteList by e.g.: byteList[2] = 3 reflects the change into the underlying array.
Now I want to expose the same (or similar) segment of the original array (byte[]) as IList<ushort> instead, like e.g.:
IList<ushort> wordlist = new ArraySegment<ushort>(bytes, 10, 5); // Note half the count compared to the byteList

This doesn't work, is this or something similar possible to do (without copying due to performance) ?
The idea is of course that 1 pcs ushort spans 2 pcs bytes.


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>