Vb.net 访问词典的另一种方式

Vb.net 访问词典的另一种方式,vb.net,dictionary,stack-overflow,Vb.net,Dictionary,Stack Overflow,这是我的代码,我正在寻找一种不同的方法来访问字典,这是另一种方法,因为堆栈溢出。尽管调试和设置断点,但仍无法找到错误。当我使用 将教育作为新词典(字符串、列表(字符串)) 它工作得很好,但这一次给我带来了问题。你有什么建议 checkWord = replacements.Keys.ElementAt(nextCheckIndex) foundIndex = RichTextBox1.Find(checkWord, 0, RichTextBoxFinds.Who

这是我的代码,我正在寻找一种不同的方法来访问字典,这是另一种方法,因为堆栈溢出。尽管调试和设置断点,但仍无法找到错误。当我使用
将教育作为新词典(字符串、列表(字符串))

它工作得很好,但这一次给我带来了问题。你有什么建议

        checkWord = replacements.Keys.ElementAt(nextCheckIndex)

        foundIndex = RichTextBox1.Find(checkWord, 0, RichTextBoxFinds.WholeWord)
        If foundIndex > -1 Then
            ContextMenuStrip1.Items.Clear()
            For Each replacement In replacements(checkWord)

你在说什么错误?你有什么问题?我不是一个读心术的人,我也没有水晶球看你的屏幕。请你准确地解释你的错误,上面的代码似乎没有任何错误。@steve。我在这里得到一个堆栈溢出:foundIndex=RichTextBox1.Find(checkWord,0,RichTextBoxFinds.WholeWord)checkWord的值是多少?您确定richtextbox文本中存在此单词吗?没有理由使用Find获取StackOverflow异常。在到达异常之前,尝试使用调试器并检查变量的值。顺便问一下,您是否确定异常是StackOverflowException,而不是来自前一行(ElementAt…)@steve的IndexOutoforFrangeException。它不是索引超出范围。当搜索大于列表大小的索引时,会出现IndexOutfrange。checkWord的值是与字典匹配的单词。Dim checkWord As String=replacements.Keys.ElementAt(nextCheckIndex)额外的下一个不应该存在,而是为了更正。谢谢但是,当您在此处删除此部分时,它没有显示上下文菜单:
Else nextCheckIndex=nextCheckIndex+1 CheckForReplacementText()如果
您能帮我解决这个问题吗?似乎这一部分对运行程序非常重要。
Private Sub CheckForReplacementText()

    Dim foundIndex As Integer = 0
    Dim start As Integer = 0

    Try
        For Each checkWord In replacements.Keys

          foundIndex = RichTextBox1.Find(checkWord, start, RichTextBoxFinds.WholeWord)
          If foundIndex > -1 Then
              ContextMenuStrip1.Items.Clear()
              For Each replacement In replacements(checkWord)

                  ContextMenuStrip1.Items.Add(replacement, Nothing, Sub(sndr As Object, ea As EventArgs)
                                                                    RichTextBox1.SelectedText = GetWordWithOutBracketedText(kamau)
                                                                End Sub)

                  ContextMenuStrip1.Show(RichTextBox1, RichTextBox1.GetPositionFromCharIndex(RichTextBox1.SelectionStart + RichTextBox1.SelectionLength))
              Next
          End If
        Next

    Catch e As Exception
        MessageBox.Show(e.ToString)
    End Try
End Sub