对DataTable里面的数据进行去重
DataTable dt = new DataTable(); dt.Columns.Add("Id", typeof(int)); dt.Columns.Add("Nu", typeof(int)); Random r = new Random(DateTime.Now.Millisecond); //DataTable 去重 for (int i = 0; i < 11; i++) { dt.Rows.Add(r.Next(1, 11),10); } dt.Rows.Add(1); DataView dv = new DataView(dt); dt = dv.ToTable(true, new string[] {"Id","Nu"}); //对Id,Nu 进行过滤,true表示使用distinct方法 foreach (DataRow item in dt.Rows) { Console.WriteLine(item["Id"].ToString()); }