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());
                            }

 

posted @ 2010-03-31 11:28  迪卡.凯恩  阅读(156)  评论(0编辑  收藏  举报