using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CXGC { public class D_N { public string name { get; set; } public DateTime dt { get; set; } } class Program { static void Main(string[] args) { List<string> ls = new List<string>(); List<D_N> ldn = new List<D_N>(); ldn.Add(new D_N() {name="张安",dt=DateTime.Now.Date }); ldn.Add(new D_N() { name = "张安", dt = DateTime.Now.AddDays(1).Date }); ldn.Add(new D_N() { name = "张安", dt = DateTime.Now.AddDays(2).Date }); ldn.Add(new D_N() { name = "张安", dt = DateTime.Now.AddDays(4).Date }); ldn.Add(new D_N() { name = "张安", dt = DateTime.Now.AddDays(4).Date }); ldn.Add(new D_N() { name = "张安", dt = DateTime.Now.AddDays(5).Date }); ldn.Add(new D_N() { name = "李思思", dt = DateTime.Now.AddDays(1).Date }); ldn.Add(new D_N() { name = "李思思", dt = DateTime.Now.AddDays(3).Date }); ldn.Add(new D_N() { name = "李思思", dt = DateTime.Now.AddDays(4).Date }); ldn.Add(new D_N() { name = "李思思", dt = DateTime.Now.AddDays(5).Date }); ldn.Add(new D_N() { name = "李思思", dt = DateTime.Now.AddDays(6).Date }); ldn.Add(new D_N() { name = "李思思", dt = DateTime.Now.AddDays(11).Date }); var ldl = ldn.OrderBy(a => a.dt).GroupBy(a => a.name).ToList(); for (int i = 0; i < ldl.Count; i++) { int num = 0; var objlist = ldl[i].ToList(); for (int j = 0; j < objlist.Count; j++) { if (j + 1 < objlist.Count) { if (objlist[j].dt.AddDays(1).Date == objlist[j + 1].dt) num++; else num = 0; } } if (num > 4) ls.Add(objlist[i].name); } //AnimalFactoryMethod am = new AnimalFactoryMethod(); //am.CreateDog().Call(); //am.CreateCat().Call(); //Console.ReadLine(); } } }