解决方案 »

  1.   

    没看懂+1,不过估计可以直接用Linq搞定……
      

  2.   

    看不懂,看着像要把list中的日期按规则归类
    根据规则自己遍历一下,拼起来就是了
      

  3.   

    本帖最后由 caozhy 于 2014-10-14 10:49:01 编辑
      

  4.   

    本质上这个问题和
    http://bbs.csdn.net/topics/390899192
    是一样的。
      

  5.   

    汗哦  就比如这种 的  
    list [int] list = new List<int>(){2,3,5,6,7,8,10,12,13}
    隔行相差1就在一组
    {2,3}就是一组
    5与前面不匹配了嘛 
    然后5 6 7 8 又是相差1 又是一组 {5,6,7,8}
    10与8和12都不差1 又是一组{10}
    12与13又相差1 又是一组{12,13}  就是这种效果嘛 求大神解答
      

  6.   

    手写的,没测试,仅供参考
    List<DateTime> li = new List<DateTime>(){ DateTime.Parse(2014/10/7 00:15:00),
                                                                          DateTime.Parse(2014/10/7 23:15:00),
                                                                          DateTime.Parse(2014/10/7 23:30:00),
                                                                          DateTime.Parse(2014/10/7 23:45:00),
                                                                          DateTime.Parse(2014/10/8 00:00:00),
                                                                          DateTime.Parse(2014/10/8 00:15:00),
                                                                          DateTime.Parse(2014/10/9 03:15:00),
                                                                          DateTime.Parse(2014/10/10 02:30:00),
                                                                          DateTime.Parse(2014/10/10 02:45:00),
                                                                       };
    DateTime pre= DateTime.MinValue;
    List<List<DateTime>> liRes = new List<List<DateTime>>();
    foreach(DateTime dt in li)
    {
        if (new TimeSpan(dt.Ticks - pre.Ticks).TotalMinutes > 15)
       {
           List<DateTime> l = new List<DateTime>();
          liRes.Add(l);
         pre=dt;
       }
        liRes[liRes.Count-1].Add(dt);
    }//输出结果
    foreach(List<DateTime> l in liRes)
    {
          foreach(DateTime dt in l)
         {
              Console.Write("{0}-", dt);
        }
        Console.WriteLine();
    }