var path = @"D:\test\1.CSV"; var records = OpenExcel(path); var groupByFirst = new List<Test> { }; var groupBySecond = new List<Test> { }; groupByFirst = records.GroupBy(x => x.D).Select(x => x.First()).ToList(); groupBySecond = records.GroupBy(x => x.D).Select(x => x.Last()).ToList(); DataTable dt = new DataTable(); dt.Columns.Add("cishu"); dt.Columns.Add("point"); Test tmpS = new Test(); var keyList = new List<string> { }; foreach(Test s in groupByFirst) { dt.Columns.Add(s.D); tmpS = s; } var propertties = tmpS.GetType().GetProperties(); for (var i = 0; i < propertties.Length; i++) { if(propertties[i].Name != "D") { DataRow newRow; newRow = dt.NewRow(); newRow["cishu"] = "1"; newRow["point"] = propertties[i].Name; dt.Rows.Add(newRow); keyList.Add(propertties[i].Name); } }
标签:newRow,C#,propertties,获取,Add,var,new,dt,属性 From: https://www.cnblogs.com/ydc2023/p/16995758.html