Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


VB.NET 1.1 - efficient way to search in an array List of objects

Posted on 2009-05-13
Medium Priority
Last Modified: 2013-11-07
Vb.net 1.1 -Searching an object item inside an array list of objects
Is there an efficient and fast way to search an object item inside an array list of objects in .net 1.1? In details&..
I have a class like (See Code Below) -
Public Class MyClass1
    Private MyID As String = ""
    Private MyName As String = ""
    Private MyAddress As String = ""
    Public Property ID() As String
            Return MyID
        End Get
        Set(ByVal Value As String)
            MyID = Value
        End Set
    End Property
    Public Property Name() As String
            Return MyName
        End Get
        Set(ByVal Value As String)
            MyName = Value
        End Set
    End Property
    Public Property Address() As String
            Return MyAddress
        End Get
        Set(ByVal Value As String)
            MyAddress = Value
        End Set
    End Property
End Class
And I want to search by Name say 'MyFirstName' from an array list of objects of type MYClass1 as -
 Dim arrlMyClass1 As ArrayList		'a large array list of objects of type MyClass1
 Dim objMyObject As New MyClass1
 Dim MyID As String = ""
 For Each objMyObject In arrlMyClass1
     If Trim(LCase("MyFirstName")) = Trim(LCase(objMyObject.Name)) Then
        MyID = objMyObject.ID
        Exit For
     End If
I am looking for an efficient search method to replace the above to search an object by item Name - say 'MyFirstname'. The For each loop is taking a lot of time if the array list is large.

Open in new window

Question by:Gurunathans
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 10

Accepted Solution

MaxOvrdrv2 earned 2000 total points
ID: 24376139
because you declared it as a class, there is no efficient way of doing that...

however, you could always define a function in your class that does it for you.. something like this:
Public Class MyClass1
Public Function Find(ByVal Lst AS ArrayList, ByVal FN AS String) As String
Dim Itm AS ListItem
Dim retval as String
For Each Itm In arrlMyClass1
If Trim(LCase(FN)) = Trim(LCase(Itm.Name)) Then
  retval="Person Found!"
End If
if retval="" then
  return "Not Found!"
  return retval
end if
End function

Open in new window


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question