//对字符串进行分割
public List<List<long>> lambda_and_linq01(long[] datas)
{
List<List<long>> groups = new List<List<long>>();
long t = long.MinValue;
foreach (long x in datas)
{
if (x - t > 1 || groups.Count == 0)
{
List<long> tl = new List<long>();
tl.Add(x);
groups.Add(tl);
}
else
{
groups[groups.Count - 1].Add(x);
}
t = x;
}
return groups;
}
//string 数组转换long数组
public static long[] convertionToLong(string[] strs)
{
// 将String数组转换为Long类型数组
long[] longs = new long[strs.Length]; //声明long类型的数组
for (int i = 0; i < strs.Length; i++)
{
String str = strs[i]; //将strs字符串数组中的第i个值赋值给str
long thelong = Convert.ToInt64(str);//将str转换为long类型,并赋值给thelong
longs[i] = thelong;//将thelong赋值给 longs数组中对应的地方
}
return longs; //返回long数组
}
/*
*
* 调用部分
*/
long[] testcount = convertionToLong(ticketcount);
List<List<long>> groups = lambda_and_linq01(testcount);
foreach (List<long> group in groups)
{
group.Sort();
StringBuilder txtBuilder = new StringBuilder();
foreach (long i in group)
{
txtBuilder.Append(i.ToString() + "\t");
}
lib_ticket.Items.Add(group[0].ToString() + "---" + group[group.Count - 1].ToString());
}
本文介绍了一种将字符串数组转换为长整型数组的方法,并提供了一个示例函数。此外,还展示了如何对长整型数组进行分组,通过遍历数组并根据元素之间的距离来创建分组,最后对每个分组进行排序。

被折叠的 条评论
为什么被折叠?



