62,272
社区成员
发帖
与我相关
我的任务
分享
public class model
{
private string _name;
private Myenum _type;
private DateTime _addtime;
public string Name
{
get { return _name; }
set { _name = value; }
}
public Myenum Type
{
get { return _type; }
set { _type = value; }
}
public DateTime AddTime
{
get { return _addtime; }
set { _addtime = value; }
}
}
protected void Page_Load(object sender, EventArgs e)
{
string[,] str = new string[3, 2];
for (int a = 0; a < 2; a++)
{
str[0, a] = "sdf" + a;
str[1, a] = (1 + a).ToString();
str[2, a] = DateTime.Now.ToString();
}
IList<model> list = CreateModelList(str);
Response.Write(list.Count);
}
protected IList<model> CreateModelList(string[,] str)
{
PropertyInfo[] pros = typeof(model).GetProperties();
IList<model> modelList = new List<model>();
for (int b = 0; b < str.GetLength(1); b++)
{
model m = new model();
for (int a = 0; a < pros.Length; a++)
{
pros[a].SetValue(m, str[a, b], null);
}
modelList.Add(m);
}
return modelList;
}
