静夜思之将一组数据按另一组数据中的值分组

本来很简单的东西,楞是想了许久。

比如将12个文件按照limts的值分为三组,

files.AddRange(new string[12] { "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12" });
 limts.AddRange(new int[3] { 4, 4, 4 });

以字符串name和names分组储存,

name = "";
int limtindex = 0;
int maxindex = limts[limtindex] - 1;
for (int i = 0; i < files.Count; i++)
{
    name += files[i] + "&&";
    if (i == maxindex && i != files.Count - 1)
    {
        names.Add(name);
        limtindex++;
        name = "";
        maxindex += limts[limtindex];
    }
}
posted @ 2022-04-27 23:20  シシヌ  阅读(31)  评论(0编辑  收藏  举报