【问题标题】:Dictionary(Of String, String) Cannot Evaluate Expression字典(字符串,字符串)无法评估表达式
【发布时间】:2015-03-13 20:16:43
【问题描述】:

当调用 Sub 以使用 DictionaryEntry() 中的键和值填充 System.Collections.Generic.Dictionary 时,在调试模式下检查 Dictionary 时,每个属性都有一个带有 X 的红色圆圈并包含文本“无法评估表达式。”它似乎正在工作,如果我尝试添加两个具有相同键/值对的条目,它甚至会抱怨。即使填充了我的测试字符串 (valuesString),也不存在任何键或值。

我从 FormView 的 ItemInserted 事件中调用 Sub(.Net Framework 4,Visual Studio 2013 Webforms 应用程序)

Protected Sub PopulateDictionary(myValues As DictionaryEntry())

        Dim de As DictionaryEntry
        Dim valuesString As String = String.Empty
        Dim myDictionary As New Dictionary(Of String, String)

        For Each de In myValues

            'This works - the string is populated with key/value pairs
            valuesString &= "Key=" & de.Key.ToString() & ", " & _
              "Value=" & de.Value.ToString() & "<br/>"

            'This doesn't - just get the red circle with an X
            myDictionary.Add(de.Key.ToString(), de.Value.ToString())

        Next
End Sub

这里发生了什么?我重新启动了 Visual Studio,但没有成功。

【问题讨论】:

  • 我确实通过从 SqlDataSourceStatusEventArgs 传入参数集合来解决这个问题。我仍然不确定为什么 Dictionary 无法在 ItemInserted 事件中工作,所以我希望也许有人对此有答案。

标签: asp.net vb.net dictionary webforms


【解决方案1】:

奇怪的是,这适用于 "&lt;br/&gt;"。看起来它缺少结束语。 (也许不需要 ToString() ?)

valuesString &= "Key=" & de.Key.ToString() & ", " & _
          "Value=" & de.Value.ToString() & "<br/>"

看起来像这样:

myDictionary.Add(de.Key.ToString(), de.Value.ToString())

只需要:

myDictionary.Add(valuesString)

或者(不确定...):

myDictionary.Add(DictionaryEntry())

【讨论】:

    猜你喜欢
    • 2016-04-24
    • 1970-01-01
    • 1970-01-01
    • 2012-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    相关资源
    最近更新 更多