using System; using System.Text; using System.Data; using System.Collections.Generic; namespace ExtensionMethods { /// /// Add extensions to /// public static class DataTableExtensions { /// /// Converts the first column of the specified to a /// /// /// /// public static List ToList(this DataTable dataTable) { return ToList(dataTable, 0); } /// /// Converts the column with the specified of the specified to a /// /// /// /// Name of the column that shall be converted /// public static List ToList(this DataTable dataTable, string columnName) { return ToList(dataTable, dataTable.Columns.IndexOf(columnName)); } /// /// Converts the column with the specified of the specified to a /// /// /// /// Index of the column that shall be converted /// public static List ToList(this DataTable dataTable, int columnIndex) { List list = new List(dataTable.Rows.Count); foreach (DataRow row in dataTable.Rows) list.Add((T)Convert.ChangeType(row[columnIndex], typeof(T))); return list; } } }