我有一个“字典”数据库,我想从特定位置返回一个元素。我看到有“ElementAt”功能,但我没有设法使用它。
为什么这样的东西不起作用?
closeHash.ElementAt<State>(i);
它告诉我以下错误:
错误 3 'System.Collections.Generic.Dictionary' 不包含 'ElementAt' 的定义,并且最佳扩展方法重载 'System.Linq.Queryable.ElementAt(System.Linq.IQueryable, int)' 有一些无效参数
而且这段代码也不起作用,因为 closeHash[i] 只给我索引而不是实际元素:
if (closeHash.ContainsKey(i) && ((State)closeHash[i]).getH() +
((State)closeHash[i]).getG() > checkState.getH() + checkState.getG()
Dictionary 中的每个元素都属于“State”类,并且 checkState 也是具有 GetH 和 GetG 函数的 State。我想取出第 Ith 位置的元素并对其进行处理,而不仅仅是删除它。
提前致谢!
格雷格