gpt4 book ai didi

vb.net - SortedList“无法比较数组中的两个元素”

转载 作者:行者123 更新时间:2023-12-02 06:16:51 27 4
gpt4 key购买 nike

其中一位使用我编写的协议(protocol)生成工具的人报告了一个我无法真正理解的错误:

Failed to compare two elements in the array. 

我使用 SortedList 来保存协议(protocol)的所有问题,并在特殊比较器中使用以下排序方法对它们进行排序:

Public Function Compare(x As String, y As String) As Integer Implements IComparer(Of String).Compare

Dim val1BiggerVal2 As Integer = 0

Dim subkeysVal1 As String() = x.Split("_"c)
Dim subkeysVal2 As String() = y.Split("_"c)
Dim rxNumberOnly As Regex = New Regex("^[0-9]+$")
Dim leftTaskgroup, leftParent, leftKey, leftID, leftCompstring, rightTaskgroup, rightParent, rightKey, rightID, rightCompstring As String
leftCompstring = ""
For counter As Integer = 0 To subkeysVal1.Length - 5
leftCompstring &= subkeysVal1(counter)
Next
leftTaskgroup = subkeysVal1(subkeysVal1.Length - 4)
leftParent = subkeysVal1(subkeysVal1.Length - 3)
leftKey = subkeysVal1(subkeysVal1.Length - 2)
leftID = subkeysVal1(subkeysVal1.Length - 1)

rightCompstring = ""
For counter As Integer = 0 To subkeysVal1.Length - 5
rightCompstring &= subkeysVal2(counter)
Next
rightTaskgroup = subkeysVal2(subkeysVal2.Length - 4)
rightParent = subkeysVal2(subkeysVal2.Length - 3)
rightKey = subkeysVal2(subkeysVal2.Length - 2)
rightID = subkeysVal2(subkeysVal2.Length - 1)

val1BiggerVal2 = compareSubstring(leftCompstring, rightCompstring)
'If Components where the same, check Taskgroups
If (val1BiggerVal2 = 0) Then
val1BiggerVal2 = compareSubstring(leftTaskgroup, rightTaskgroup)
End If
'If Taskgroups where the same, check parent-child relation
If (val1BiggerVal2 = 0) Then
If rightKey = leftParent Then
val1BiggerVal2 = 1
ElseIf rightParent = leftKey Then
val1BiggerVal2 = -1
ElseIf rightParent = leftParent Then
val1BiggerVal2 = compareSubstring(leftKey, rightKey)
Else
Dim Left As String = leftParent
Dim Right As String = rightParent
If leftParent = "" Then
Left = leftKey
End If
If rightParent = "" Then
Right = rightKey
End If

val1BiggerVal2 = compareSubstring(Left, Right)
End If
End If
'if even the parent-child relation wasnt unquie, use the autoincremented endvalue
If val1BiggerVal2 = 0 Then
val1BiggerVal2 = leftID.compareTo(rightID)
End If
Return val1BiggerVal2

End Function

我认为通过最后一次检查,如果 val1biggerVal2 为 0,我应该始终获得唯一的标识,因为每次我读取问题时,最后一个 _ID 都会自动增加输入文件。

最佳答案

经过几个小时的思考,没有进一步的线索,我决定简单地用 SortedDictionary 数据结构替换我的 SortedList
这解决了问题,但如果有人知道为什么带有 SortedList 的版本不起作用,请告诉我。

关于vb.net - SortedList“无法比较数组中的两个元素”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22685064/

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