Hashtable怎样根据Key取value
U0015Model.cs
public class U0015Model
{
public Hashtable SelectDate(string year)
{
string hql1 = "select distinct a.Bcscalmouth from Bcscalendar a where a.Bcscalyear='"+year+"' and a.Bcscalisrest='1'";
string hql2 = "select a.Bcscalday from Bcscalendar a where a.Bcscalyear='"+year+"' and a.Bcscalisrest='1'";
BCSDB db = new BCSDB();
IList list1 = db.selectHql(hql1);
IList list2 = db.selectHql(hql2);
Hashtable ht = new Hashtable();
ht.Add(list1,list2);
return ht;
}
}
U0015.aspx.cs
protected void receive(int year,int month)
{
U0015Model u0015 = new U0015Model();
Hashtable ht = new Hashtable();
ht = u0015.SelectDate(ddlstSelectYear.SelectedValue);
object obj = ht["01"];
}
在U0015Model.cs中从数据库中取出数据,放到Hashtable里.现在Key为"01","02",如何根据键值取出对应的Value?
[解决办法]
Hashtable hashtable = new Hashtable();
hashtable.Add("1", "1001");
Response.Write(hashtable["1"]);
结果为:1001
[解决办法]
就这样呗:ht["01"]
不过取出来的是object类型,你还要进行类型转换
[解决办法]