Dynamic type for List<T>?
Posted
by Brett
on Stack Overflow
See other posts from Stack Overflow
or by Brett
Published on 2010-04-30T12:43:39Z
Indexed on
2010/04/30
12:47 UTC
Read the original article
Hit count: 417
Hi All,
I've got a method that returns a List for a DataSet table
public static List<string> GetListFromDataTable(DataSet dataSet, string tableName, string rowName)
{
int count = dataSet.Tables[tableName].Rows.Count;
List<string> values = new List<string>();
// Loop through the table and row and add them into the array
for (int i = 0; i < count; i++)
{
values.Add(dataSet.Tables[tableName].Rows[i][rowName].ToString());
}
return values;
}
Is there a way I can dynamically set the datatype for the list and have this one method cater for all datatypes so I can specify upon calling this method that it should be a List<int
> or List<string>
or List<AnythingILike>
?
Also, what would the return type be when declaring the method?
Thanks in advance, Brett
© Stack Overflow or respective owner