【发布时间】:2017-07-31 15:40:30
【问题描述】:
所以我使用 ArrayLists 来存储一些整数数组,我想出了以下问题:
Public Class Form1
Public ag As New ArrayList
Sub a() Handles Me.Load
ag.Add(New Integer() {1, 2})
If ag.Contains(New Integer() {1, 2}) Then
MsgBox("aaa")
End If
End Sub
End Class
尽管 ArrayList 确实包含“New Integer() {1, 2}”,但 MsgBox 不会显示,即使我尝试这样做:
Public Class Form1
Public ag As New ArrayList
Sub a() Handles Me.Load
ag.Add(New Integer() {1, 2})
Dim t = New Integer() {1, 2}
For Each it In ag
If it.Equals(t) Then
MsgBox("aa")
Exit For
End If
Next
End Sub
End Class
它根本不会显示。
提前致谢。
---------------编辑---------------
我最终决定像这样比较整数列表的值:
Public Class Form1
Public ag As New List(Of Integer())
Sub a() Handles Me.Load
ag.Add(New Integer() {1, 2})
Dim t = New Integer() {1, 2}
For Each it In ag
If it(0) = t(0) And it(1) = t(1) Then
MsgBox("aa")
Exit For
End If
Next
End Sub
End Class
谢谢大家的回复。
【问题讨论】:
-
在哪里比较 'ag' 和 'New Integer() {1, 2}'?
-
不要使用 ArrayList
-
我比较了 'ag' 的内容和 'New Integer() {1, 2}'
-
我还能用什么?
-
你没有比较/测试任何东西的内容。
New Integer() {1, 2}创建一个 new 数组