日期:2014-05-20 浏览次数:21026 次
public class ImportLog { /// <summary> /// Excel行号 /// </summary> public int RowID { get; set; } /// <summary> /// 当前行中每个单元格的值 /// </summary> public List<object> FieldList { get; set; } /// <summary> /// 是否包含错误 /// </summary> public bool HasError { get; set; } /// <summary> /// 错误信息 /// </summary> public string ErrorMsg { get; set; } }
public List<ImportLog> GetRepeatedRows(List<ImportLog> list = null) { if (list == null) { list = new List<ImportLog>() { new ImportLog(){ RowID=1, FieldList=new List<object>(){"1","11","111"}, ErrorMsg=""}, new ImportLog(){ RowID=2, FieldList=new List<object>(){"1","11","111"}, ErrorMsg=""}, new ImportLog(){ RowID=3, FieldList=new List<object>(){"1","11","111","1111"}, ErrorMsg=""}, new ImportLog(){ RowID=4, FieldList=new List<object>(){"1","11","111","1112"}, ErrorMsg=""}, new ImportLog(){ RowID=5, FieldList=new List<object>(){"1","11","112","1121"}, ErrorMsg=""}, new ImportLog(){ RowID=6, FieldList=new List<object>(){"1","11","112","1121"}, ErrorMsg=""}, new ImportLog(){ RowID=7, FieldList=new List<object>(){"1","12","121","1211"}, ErrorMsg=""}, new ImportLog(){ RowID=8, FieldList=new List<object>(){"1","12","122","1221"}, ErrorMsg=""}, new ImportLog(){ RowID=9, FieldList=new List<object>(){"1","13","131","1311"}, ErrorMsg=""}, new ImportLog(){ RowID=10, FieldList=new List<object>(){"2","21","211","2111"}, ErrorMsg=""}, new ImportLog(){ RowID=11, FieldList=new List<object>(){"2","21","211","2111"}, ErrorMsg=""}, new ImportLog(){ RowID=11, FieldList=new List<object>(){"2","21","211","2111"}, ErrorMsg=""}, }; } //方式1:成功,但效率貌似不高 //var ret1 = list.FindAll(a => list.FindAll(b => b.FieldList.Intersect(a.FieldList).Count() == a.FieldList.Count).Count > 1); //方式2:group by m.FieldList into g 失败 var ret2 = (from t in list where ( from d in ( from m in list group m by m.FieldList into g where g.Count() > 1 select g ) select d.Key ).Contains(t.FieldList) select t).ToList(); var count = ret2.Count;//count=0 …… return ret2; }