가. 언어유형/C#
[C#] List<T>에서 Byte[]로 변경
LemonDory
2019. 7. 17. 10:32
출처 : https://stackoverflow.com/questions/34884854/convert-listint-to-byte
Convert list<int[]> to byte[]</int[]>
How to convert list<int[]> to byte[]? I could use this: byte[] bytes = lista.SelectMany(BitConverter.GetBytes).ToArray(); But it works only for list. If you have few ideas - m...</int[]>
stackoverflow.com
List -> byte[]
byte[] bytes = lista .SelectMany(x => x) .SelectMany(BitConverter.GetBytes) .ToArray();
byte[] -> List
List<int> list = bytes
.Select((item, index) => new {item, index})
.GroupBy(x => x.index/4)
.Select(g => g.Select(x => x.item).ToArray())
.Select(x => BitConverter.ToInt32(x, 0)) .ToList();