gpt4 book ai didi

asp.net - 获取排序列表中的最大键

转载 作者:行者123 更新时间:2023-12-02 15:22:37 27 4
gpt4 key购买 nike

如何确定 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

https://dotnetfiddle.net/l1d3AF

关于asp.net - 获取排序列表中的最大键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34007575/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com