我有一个函数返回我的 int 值列表取决于值的一部分:
private List<int> GetColumn(int total, int column)
{
List<int> retList = new List<int>();
if (total <= 0)
{
return retList;
}
if (column < 0 || column > 2)
{
column = 0;
}
int pageSize = total / 3;
int startIndex = column * pageSize;
int endIndex = column * pageSize + pageSize;
if (endIndex > total)
{
endIndex = total;
}
for (int i = startIndex; i < endIndex; i++)
{
retList.Add(i);
}
return retList;
}
但它工作错误,因为:GetColumn(17, 0)
它返回 [0,1,2,3,4],但应该
为 GetColumn(17, 1) - [6,7,8,9,10,11返回 [0,1,2,3,4,5] ]
for GetColumn(17, 2) - [12,13,14,15,16]
对于 16,它应该返回:对于 GetColumn(16, 0) - [0,1,2,3,4,5]
对于 GetColumn(16, 1) - [6,7,8,9,10]
对于 GetColumn(16 , 2) - [11,12,13,14,15]
我应该改变我的功能?谢谢!