Converting values for a DataColumn to an Array

I was asked this question today: is there an easy way (i.e. single method call) to convert the row values for a particular DataColumn of a DataTable into a String array. I don’t necessarily recommend doing this, but yes:

String[] rowValuesForColumn =
 Array.ConvertAll<DataRow, String>(
   dataTable.Select(),
   delegate(DataRow row) { return (String) row[columnName]; }
 );

You can obviously package all this into a generic method to convert to any type of array.

Comments