/// <summary>
/// 分批算法
/// </summary>
static void Segmentation()
{
string[] t = new string[43];
for (int i = 0; i < 43; i++)
{
t[i] = i.ToString();
}
if (t.Length > 2)
{
double page = Math.Ceiling(t.Length * 1.0 / 20);
for (int p = 1; p <= page; p++)
{
//循环每一页
for (int index = (p - 1) * 20; index < p * 20 && index < t.Length; index++)
{
System.Console.WriteLine(t[index]);
}
System.Console.WriteLine("---------------------------");
}
}
System.Console.ReadKey();
}
优化之后
/// <summary>
/// 分批算法
/// </summary>
static void Segmentation()
{
string[] t = new string[43];
for (int i = 0; i < 43; i++)
{
t[i] = i.ToString();
}
if (t.Length > 2)
{
double page = Math.Ceiling(t.Length * 1.0 / 20);
for (int p = 1; p <= page; p++)
{
string s = string.Join(",", t.Skip((p - 1) * 20).Take(20).ToArray());
System.Console.WriteLine(s);
System.Console.WriteLine("---------------------------");
}
}
System.Console.ReadKey();
}