Hi, I am trying to create a method that takes a DataTable or a DataRowCollection and converts it to an array of a generic type. Something like this:
public static T[] ConvertToArray<T>(DataTable dataTable)
{
List<T> result = new List<T>();
foreach (DataRow dataRow in dataTable.Rows)
result.Add((T)dataRow);
return result.ToArray();
}
The problem is this line
result.Add((T)dataRow);
which gives Cannot convert System.Data.DataRow to T.
If I do the same thing without using a generic type, and make sure the class of the objects have a defined custom conversion operator, the code works fine.
So the question is now, how do I pull this of using generics?