2010-03-31日使用到的几个方法!

        //对字符串进行分割
        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());
                            }

 

转载于:https://www.cnblogs.com/Deckard/archive/2010/03/31/1701210.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值