如何确定 SortedList 中的最大键是多少?我已尝试使用 SortList.Max 方法,但无法正常工作。
示例代码如下:
Dim MySortedList As New SortedList(Of Int16, String)
MySortedList.Add(1, "Item 1")
MySortedList.Add(2, "Item 2")
MySortedList.Add(3, "Item 3")
MySortedList.Add(4, "Item 4")
'I added this just to demonstrates the sorted list is working
Response.Write(MySortedList(4))
'Now... how to I get the max 'Key' from the sorted list?
'In this example I want it to return the number '4'.
Dim MyMaxKey = MySortedList.Max <---- This doesn't work. Added as an example.
Response.Write(MyMaxKey)
最佳答案
由于 SortedList 按键排序,您可以简单地获取最后一项的键 - 这是最大键:
Dim MyMaxKey = MySortedList.Last().Key
关于asp.net - 获取排序列表中的最大键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34007575/