不能使用linq"Last()"方法

jen*_*gar -2 c# linq

我不太了解C#,但我有这个项目,我正在努力做我想做的事情:

SortedDictionary<int, List<ChessMove>> possibleMovesByRank = new SortedDictionary<int, List<ChessMove>>();
...
var best = possibleMovesByRank.Keys.Last();
Run Code Online (Sandbox Code Playgroud)

从我能够找到的,这应该使用linq返回具有最高值的键,但VS给我一个错误:

SortedDictionary.KeyCollection does not contain a definition for 'Last' and no extension method for 'Last'
Run Code Online (Sandbox Code Playgroud)

我错过了什么或者我的项目设置不正确还是什么?

Aar*_*ano 5

最有可能的是,您缺少C#文件中的System.Linq命名空间.这是一个扩展方法Enumerable.Last将不存在,除非您包含相关的命名空间.