下一个循环中的可变声明语法错误
以下代码正常工作。
Private Sub Button1_Click(sender As Object, e As RoutedEventArgs) Handles Button1.Click
Dim Dictionary1 As New Dictionary(Of String, Integer)
Dim Dictionary2 As New Dictionary(Of String, Integer)
Dim Dictionary3 As New Dictionary(Of String, Integer)
Dim Dictionary4 As New Dictionary(Of String, Integer)
Dim Dictionary5 As New Dictionary(Of String, Integer)
Dictionary1.Add("George", "36")
Dictionary2.Add("George", "36")
Dictionary3.Add("George", "36")
Dictionary4.Add("George", "36")
Dictionary5.Add("George", "36")
End Sub
我试图像下一个循环那样缩短上述代码,例如以下代码。
但是以下代码给了我一个错误。
Private Sub Button2_Click(sender As Object, e As RoutedEventArgs) Handles Button2.Click
Dim Dictionary1 As New Dictionary(Of String, Integer)
Dim Dictionary2 As New Dictionary(Of String, Integer)
Dim Dictionary3 As New Dictionary(Of String, Integer)
Dim Dictionary4 As New Dictionary(Of String, Integer)
Dim Dictionary5 As New Dictionary(Of String, Integer)
For i As Integer = 1 To 5
("Dictionary" & i).Add("George", "36")
Next
End Sub
那么,如何解决以下错误?
Following code is working properly.
Private Sub Button1_Click(sender As Object, e As RoutedEventArgs) Handles Button1.Click
Dim Dictionary1 As New Dictionary(Of String, Integer)
Dim Dictionary2 As New Dictionary(Of String, Integer)
Dim Dictionary3 As New Dictionary(Of String, Integer)
Dim Dictionary4 As New Dictionary(Of String, Integer)
Dim Dictionary5 As New Dictionary(Of String, Integer)
Dictionary1.Add("George", "36")
Dictionary2.Add("George", "36")
Dictionary3.Add("George", "36")
Dictionary4.Add("George", "36")
Dictionary5.Add("George", "36")
End Sub
I have tried to shorten the above code like the below code via for next loop.
But the below code gives me an error.
Private Sub Button2_Click(sender As Object, e As RoutedEventArgs) Handles Button2.Click
Dim Dictionary1 As New Dictionary(Of String, Integer)
Dim Dictionary2 As New Dictionary(Of String, Integer)
Dim Dictionary3 As New Dictionary(Of String, Integer)
Dim Dictionary4 As New Dictionary(Of String, Integer)
Dim Dictionary5 As New Dictionary(Of String, Integer)
For i As Integer = 1 To 5
("Dictionary" & i).Add("George", "36")
Next
End Sub
So, how can I solve the following error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
字典列表
List of Dictionary