Asp.net (字符串的)字典无法计算表达式
调用Sub以使用DictionaryEntry中的键和值填充System.Collections.Generic.Dictionary时,在调试模式下检查字典时,每个属性都有一个带X的红色圆圈,并包含无法计算表达式的文本。它似乎在工作,如果我尝试添加两个具有相同键/值对的条目,它甚至会抱怨。即使填充了我的测试字符串valuesString,也不存在任何键或值 我正在调用FormView.Net Framework 4 Visual Studio 2013 Webforms应用程序的ItemInserted事件中的SubAsp.net (字符串的)字典无法计算表达式,asp.net,vb.net,dictionary,webforms,Asp.net,Vb.net,Dictionary,Webforms,调用Sub以使用DictionaryEntry中的键和值填充System.Collections.Generic.Dictionary时,在调试模式下检查字典时,每个属性都有一个带X的红色圆圈,并包含无法计算表达式的文本。它似乎在工作,如果我尝试添加两个具有相同键/值对的条目,它甚至会抱怨。即使填充了我的测试字符串valuesString,也不存在任何键或值 我正在调用FormView.Net Framework 4 Visual Studio 2013 Webforms应用程序的ItemIns
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
这是怎么回事?我重新启动了VisualStudio,但运气不佳。奇怪的是,它可以与。看起来它缺少结束语。也许不需要ToString
valuesString &= "Key=" & de.Key.ToString() & ", " & _
"Value=" & de.Value.ToString() & "<br/>"
只是需要:
myDictionary.Add(valuesString)
或者不确定…:
myDictionary.Add(DictionaryEntry())
我确实通过从SqlDataSourceStatusEventArgs传入参数集合来解决了这个问题。我仍然不确定为什么字典在ItemInserted事件中无法工作,所以我希望有人能对此给出答案。
myDictionary.Add(DictionaryEntry())