搜索自定义数据结果的结果(Search a Custom DataClass for Results)

编程入门 行业动态 更新时间:2024-10-22 23:41:28
搜索自定义数据结果的结果(Search a Custom DataClass for Results)

我已经构建了一个存储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地址,它会将名称返回给我。

有谁知道我会怎么做?

I have built a custom Data Class that stores IP Address Details.

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

What I'm trying to figure out how to do is search it for specific data.

Example.. I send it an IP address and it will return the name to me.

Does anyone know how I would do this?

最满意答案

首先,你需要把对象放在一个集合中。 为此,您需要选择一个数据结构(即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

现在,如果您有对象的实例,则可以直接访问该属性。

First of all, you need to put the object in a collection. To do this, you need to choose a data structure (i.e. List, ArrayList, etc)

Dim Items as List(Of IPAddressDataItem)

Then, you can iterate through the collection, find the item based on the search criteria and return the data required.

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

Right now, if you have an instance of the object, you can just access the property directly.

更多推荐

本文发布于:2023-07-24 01:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1240119.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   数据   Search   Results   DataClass

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!