.Net中把Tabe转化为List
DataTable table = new DataTable();
table.Columns.Add("Id");//创建Id的列
table.Columns.Add("Name");//创建Name的列
table.Rows.Add(1, "张三");添加数据
table.Rows.Add(2, "李四");
table.Rows.Add(3, "王五");
List<UserTable> list = new List<UserTable>();//创建List
for (int i = 0; i < table.Rows.Count; i++)
{
string id = table.Rows[i]["Id"].ToString();//赋值
string name = table.Rows[i]["Name"].ToString();
UserTable userTable = new UserTable()
{
Id = Convert.ToInt32(id),
Name = name
};
list.Add(userTable);//添加
}