我想使用KeyValuePair遍历Dictionary<string, string>
对象(从域服务返回),但收到此错误消息:
类型'KeyValuePair`2'不是有效的实体类型。实体类型不能是通用的
奇怪的是,同样的代码在我的队友的机器上运行良好。不知道发生了什么事。有人可以对此有所了解吗?
private void GetCountiesCompleted(object sender, EventArgs e)
{
Dictionary<string, string> countyList = (sender as invokeOperation).Value as Dictionary<string, string>;
foreach (KeyValuePair<string, string> kv in countyList)
{
string state = kv.Value;
if (!stateList.Contains(state))
{
stateList.Add(state);
}
}
}
这是域服务定义,如果有帮助:
public Dictionary<string, string> GetSomeCounties(string year, string month)
{
Dictionary<string, string> Counties = new Dictionary<string,string>();
// loop through some data set and append to Counties
foreach (someObject item in countiesDataSet.COUNTIES)
{
Counties.Add(item.FULLNAME, item.STATE_FIPS + item.CNTY_FIPS);
}
return Counties;
}