Dictionary<TKey,TValue>
例如:Dictionary<int,string> dic
1、通过Key找value
string strValue=dic[kye];
2、通过value找key
string strValue="北京一中";
var query=from d in dic
where d.value==strValue
select d.key;
int keyint=query.FirstOrDefault();
在项目中用到的:
Dictionary<int,string> dicSchool=schoolManager.GetSchoolInfo(-1);
ddlSchoolName.DataSource = dicSchool.Values;
ddlSchoolName.DataTextField="sname";
ddlSchoolName.DataValueField="sno";
ddlSchoolName.DataBind();
Dictionary<int, string> dicSchool = schoolManager.GetSchoolInfo(-1);
string school = dsSentDictationJun.Tables["DTSentDictationJun"].Rows[i]["schoolId"].ToString();
var query = from d in dicSchool
where d.Value == school
select d.Key;
int schoolId = query.FirstOrDefault();
sentDictation.SchoolId = schoolId;
例如:Dictionary<int,string> dic
1、通过Key找value
string strValue=dic[kye];
2、通过value找key
string strValue="北京一中";
var query=from d in dic
where d.value==strValue
select d.key;
int keyint=query.FirstOrDefault();
在项目中用到的:
Dictionary<int,string> dicSchool=schoolManager.GetSchoolInfo(-1);
ddlSchoolName.DataSource = dicSchool.Values;
ddlSchoolName.DataTextField="sname";
ddlSchoolName.DataValueField="sno";
ddlSchoolName.DataBind();
Dictionary<int, string> dicSchool = schoolManager.GetSchoolInfo(-1);
string school = dsSentDictationJun.Tables["DTSentDictationJun"].Rows[i]["schoolId"].ToString();
var query = from d in dicSchool
where d.Value == school
select d.Key;
int schoolId = query.FirstOrDefault();
sentDictation.SchoolId = schoolId;