我已经构建了一个存储IP地址详细信息的自定义数据类。
Public Class IPAddressDataItem
Private _ID As Integer
Private _IP As String
Private _Name As String
Public Property ID() As Integer
Get
Return _ID
End Get
Set(ByVal value As Integer)
_ID = value
End Set
End Property
Public Property IP() As String
Get
Return _IP
End Get
Set(ByVal value As String)
_IP = value
End Set
End Property
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property\
Public Sub New(ByVal id As Integer, ByVal ip As String, ByVal name As String)
_ID = id
_IP = ip
_Name = name
End Sub
End Class
我想弄清楚怎么做才是搜索特定数据。
示例..我发送了一个IP地址,它会将名称返回给我。
有谁知道我会怎么做?
答案 0 :(得分:2)
首先,您需要将对象放入集合中。为此,您需要选择数据结构(即List,ArrayList等)
Dim Items as List(Of IPAddressDataItem)
然后,您可以遍历集合,根据搜索条件查找项目并返回所需的数据。
Function GetName(ByVal IP As String) As String
For Each Item As IPAddressDataItem In Items
If Item.IP.CompareTo(IP) = 0 Then
Return Item.Name
End If
Next
End Function
现在,如果你有一个对象的实例,你可以直接访问该属性。