Can any on开发者_StackOverflow社区e tell me how to convert the List into data table in C# ?
Do you mean generically? There is no automatic way to do it.
But you can manually:
class Person
{
public int ID {get; set;}
public string FirstName {get; set;}
...
}
var personsList = new List<Person>();
var dataTable = new DataTable();
dataTable.Columns.Add("ÏD", typeof(int));
dataTable.Columns.Add("FirstName", typeof(string));
...
foreach (var person in personsList)
{
dataTable.Rows.Add(person.ID, person.FirstName...)
}
精彩评论