public int CompareTo(Object obj) { DateYMD dymd = (DateYMD)obj; if (this.year > dymd.year) { return(1); } else if (this.year == dymd.year) { if (this.month > dymd.month) { return(1); } else if (this.month == dymd.month) { if (this.day > dymd.day) { return(1); } else if (this.day == dymd.day) { return(0); } } } return(-1); }
//LINQ //去重! void YMDDistinct() { var list = dymlist.Distinct(new DuplicateDefine()).ToList(); DateYMD dymd1 = new DateYMD(datename1); DateYMD dymd2 = new DateYMD(datename2); var dateresult = list.FindAll(x => (x.CompareTo(dymd1) == 1 && x.CompareTo(dymd2) == -1)).ToList(); dateresult.Insert(0, dymd1); dateresult.Add(dymd2); }