List 集合 一行4个排序

            List<string> list = new List<string>();
            for (int i = 0; i < 101; i++)
            {
                list.Add(i.ToString());
            }

            int j;
            if (list.Count % 4 == 0)
                j = list.Count / 4;
            else
                j = (list.Count / 4) + 1;
            
            for (int z = 1; z <= j; z++)
            {
                //z*4-4,z*4-3,z*4-2,z*4-1 <= list.count
                if (z * 4 <= list.Count)
                {
                    for (int k = z * 4 - 4; k <= z * 4 - 1; k++)
                    {
                        Console.Write(list[k] + " ");
                    }
                    Console.WriteLine("</ br>");
                }
                else
                {
                    int zz = z * 4 - list.Count;
                    for (int k = z * 4 - 4; k < z * 4 - zz; k++)
                    {
                        Console.Write(list[k] + " ");
                    }
                    Console.WriteLine("</ br>");
                }
            }

 

posted @ 2018-09-11 16:07  youguess  阅读(252)  评论(0编辑  收藏  举报