gpt4 book ai didi

c# - 将 List 拆分为 N 大小的较小列表

转载 作者:IT王子 更新时间:2023-10-29 03:30:50 25 4
gpt4 key购买 nike

<分区>

我正在尝试将一个列表拆分为一系列较小的列表。

我的问题:我的拆分列表函数没有将它们拆分为正确大小的列表。它应该将它们拆分为大小为 30 的列表,但它却将它们拆分为大小为 114 的列表?

如何让我的函数将一个列表拆分为 X 个大小为 30 或更小的列表?

public static List<List<float[]>> splitList(List <float[]> locations, int nSize=30) 
{
List<List<float[]>> list = new List<List<float[]>>();

for (int i=(int)(Math.Ceiling((decimal)(locations.Count/nSize))); i>=0; i--) {
List <float[]> subLocat = new List <float[]>(locations);

if (subLocat.Count >= ((i*nSize)+nSize))
subLocat.RemoveRange(i*nSize, nSize);
else subLocat.RemoveRange(i*nSize, subLocat.Count-(i*nSize));

Debug.Log ("Index: "+i.ToString()+", Size: "+subLocat.Count.ToString());
list.Add (subLocat);
}

return list;
}

如果我在大小为 144 的列表上使用该函数,则输出为:

Index: 4, Size: 120
Index: 3, Size: 114
Index: 2, Size: 114
Index: 1, Size: 114
Index: 0, Size: 114

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