I have a brain fart trying to make the following method more general so that any List<T> can be passed for the columnValues parameter. Here is what I have:
public static DataRow NewRow(this DataTable dataTable, List<string> columnValues) { DataRow returnValue = dataTable.NewRow(); while (columnValues.Count > returnValue.Table.Columns.Count) { returnValue.Table.Columns.Add(); } returnValue.ItemArray = columnValues.ToArray(); return returnValue; }
I could change it to List<object> and convert the original list before passing it to the method, but I'm sure there is a better option :-)
Edit:
Frank post made me rethink this. In most cases, the source of List<T> will be List<object> , since the column values ββare likely to be of different types.
For my initial use, the value of List<string> makes sense because I created a dataset from the CSV syntax, which is all the text at this point.
Cory charlton
source share