所以我有一个字节列表
List<byte> s = {1,2,3,2,2,2,3,1,2,4,2,1,4,.....};
我想使用element的索引获取新的职位列表。
List<byte> 1 = {0,7,11};
List<byte> 2 = {1,3,4,5,8,10};
List<byte> 3 = {2,6};
List<byte> 4 = {9,12};
List<byte> 5 = ..... and so on
最好的方法是什么?
谢谢。
您可以使用GroupBy
和ToDictionary
获得Dictionary<byte, List<int>>
:
var dict = s.Select((value, index) => new { value, index })
.GroupBy(x => x.value)
.ToDictionary(g => g.Key, g => g.Select(x => x.index).ToList());
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句