当用Enumerator遍历Dictionary<string, string>时,遇到返回值为空的情况,求解。
//Get the source code of the open page.
Dictionary<string, string> hrefs = UIMethods.GetDivHrefs(codeview, this.expectedContentId);
//这里为何得到的enumerator都为空,非常迷惑
Dictionary<string, string>.Enumerator enumerator = hrefs.GetEnumerator();
if (null != enumerator.Current.Value)
{
///。。
}
//Get the source code of the open page.
Dictionary<string, string> hrefs = UIMethods.GetDivHrefs(codeview, this.expectedContentId);
//这里为何得到的enumerator都为空,非常迷惑
Dictionary<string, string>.Enumerator enumerator = hrefs.GetEnumerator();
if (null != enumerator.Current.Value)
{
///。。
}
kvp.Value
{
Console.WriteLine(
string.Format("key:{0}\nvalues:{1}\n",
entry.Key,
entry.Value
)
);
}
Enumerator 默认情况下它指向的是第一个元素之前,而不是第一个元素,所以current 获取的是空
楼上已经告诉你了要先movenext