gpt4 book ai didi

c# - 将list 转换为byte []

转载 作者:太空宇宙 更新时间:2023-11-03 18:04:56 24 4
gpt4 key购买 nike

怎么把list<int[]>转换成byte[]

我可以用这个:

 byte[] bytes = lista.SelectMany(BitConverter.GetBytes).ToArray();


但是它仅适用于 list<int>。如果您有什么想法-最有效的方法就是欢迎。

最佳答案

这个怎么样:

byte[] bytes =
lista
.SelectMany(x => x)
.SelectMany(BitConverter.GetBytes)
.ToArray();


更新:

要将结果转换为 List<int>,可以执行以下操作:

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();

关于c# - 将list <int []>转换为byte [],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34884854/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com