public class JNInfoItem
{
public string[] JNName;
public Int32[] JNLestTime, JNUseTime, JNZTID;
}public List<JNInfoItem> JNItem = new List<JNInfoItem>();如何将数据加入到List<类>中
如:JNItem.Add(Name)与JNItem.Add(ID) 能一一对应的??请高手帮忙
{
public string[] JNName;
public Int32[] JNLestTime, JNUseTime, JNZTID;
}public List<JNInfoItem> JNItem = new List<JNInfoItem>();如何将数据加入到List<类>中
如:JNItem.Add(Name)与JNItem.Add(ID) 能一一对应的??请高手帮忙
{
public string JNName;
public Int32 JNLestTime;
public Int32 JNUseTime;
public Int32 JNZTID;
}然后LIST中是这个对象,这样他们就是一一对应的了。
{
int id;
public int ID { get { return this.id; } }
public string Name { get; set; }
public DateTime? LastTime { get; set; }
public DateTime? UsedTime { get; set; } public JNInfoItem(int ID)
{
this.id = ID;
} public JNInfoItem(int ID, string Name)
{
this.id = ID;
this.Name = Name;
}
} public class JNInfoList : CollectionBase
{
public JNInfoList()
{ } public int Add(JNInfoItem Item)
{
//如果ID号不能重复,这里还需检测
return this.InnerList.Add(Item);
} public int Add(int ID)
{
JNInfoItem item = new JNInfoItem(ID);
return Add(item);
} public void Remove(JNInfoItem Item)
{
this.InnerList.Remove(Item);
} public void RemoveAt(int Index)
{
this.InnerList.RemoveAt(Index);
} public void RemoveByID(int ID)
{
foreach (JNInfoItem item in this.InnerList)
{
if (item.ID == ID)
{
Remove(item);
return;
}
}
} public JNInfoItem GetItemByID(int ID)
{
foreach (JNInfoItem item in this.InnerList)
{
if (item.ID == ID)
return item;
} return null;
} public JNInfoItem this[int Index] { get { return (JNInfoItem)this.InnerList[Index]; } } //以上的是较常用的
}JNInfoList list = new JNInfoList();
list.Add(new JNInfoItem(0, "小刚"));//将一个对象加入集合
list.Add(1);//根据ID号,内部会生成一个对象,然后再加入集合
list.GetItemByID(1).Name = "小强";//刚才只传入ID号,Name是空的,可以通过获取集合中的对应的对象,再进行赋值。当然也可以用其它办法
{
public string jNName;
public Int32 jNLestTime;
public Int32 jNUseTime;
public Int32 jNZTID; public JNInfoItem(int JNZTID,int JNUseTime,string JNName)
{
this.jNName=JNName;
this.jNLestTime=JNLestTime;
this.jNUseTime=JNUseTime;
this.jNZTID=JNZTID;
}
public List <JNInfoItem> JNItem = new List <JNInfoItem>();
JNInfoItem item=new JNInfoItem();
item.JNName="name";
item.JNLestTime=45;
item.JNUseTime=35;
item.JNZTID=3;
JNItem.add(item);
}
这样就绑定起来了,取的时候将List对象转换成JNInfoItem就可以了。
public JNInfoItem(int JNZTID,int JNUseTime,string JNName)
{
this.jNName=JNName;
this.jNLestTime=JNLestTime;
this.jNUseTime=JNUseTime;
this.jNZTID=JNZTID;
}
不去掉这个就会报错.