去除DataTable中的重复数据

有时需要从DataTable中抽取Distinct数据,遍历比较费劲,C#.NET中其实有更易用的方法,如下:

string[] columnArray = { "columnName1", "columnName2" };
DataView dataView = dataTable.DefaultView;
dataTable = dataView.ToTable(true, columnArray);

或者

DataView dataView = dataTable.DefaultView;
dataTable = dataView.ToTable(true, "columnName1", "columnName2");

ToTable的去重方法定义如下:

public DataTable ToTable(bool distinct, params string[] columnNames);
public DataTable ToTable(string tableName, bool distinct, params string[] columnNames);
上一篇:Project Euler 91:Right triangles with integer coordinates 格点直角三角形


下一篇:CSS层叠样式选择器归纳