Given a read only collection of ints, how do I convert it to a byte array?
ReadOnlyCollection<int> collection = new List<int> { 118,48,46,56,46,50 }.AsReadOnly(); //v0.8.2
What will an elegant way to convert 'collection' to byte[] ?
Given a read only collection of ints, how do I convert it to a byte array?
ReadOnlyCollection<int> collection = new List<int> { 118,48,46,56,46,50 }.AsReadOnly(); //v0.8.2
What will an elegant way to convert 'collection' to byte[] ?
You can use LINQ's
Selectmethod to cast each element frominttobyte. This will give you anIEnumerable<byte>. You can then use theToArray()extension method to convert this to abyte[].If you don't want to use LINQ then you can instantiate the array and use a for loop to iterate over the collection instead, assigning each value in the array.