Results 1 to 4 of 4

Thread: [RESOLVED] [2008] How to search in System.Collections.Generic.List?

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2007
    Location
    Latvia (Small country near Baltic Sea)
    Posts
    54

    Resolved [RESOLVED] [2008] How to search in System.Collections.Generic.List?

    Well I would like to know how to find a value in the System.Collections.Generic.List.

    I have:
    Private ids As New List(Of Byte())
    ids.add(New Byte(){&HA8,&H0F})
    ids.add(New Byte(){&HFF,&H03})
    ids.add(New Byte(){&H10,&H00})

    I would like to find for example: &H10,&H00
    in that list and if there isn't the stuff I wan't to find then how do I know that?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] How to search in System.Collections.Generic.List?

    vb Code:
    1. Private Function MySearchMethod(ByVal b as Byte())
    2. 'Code here to read b and determine if it's the one you're looking for
    3. 'If it is,
    4. Return True
    5. 'else if it isn't
    6. Return False
    7. End Function


    Then use:

    vb Code:
    1. ids.Find(Addressof MySearchMethod)

  3. #3
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2008] How to search in System.Collections.Generic.List?

    You could use a linq query:
    Code:
            Dim ids As New List(Of Byte())
            ids.add(New Byte() {&HA8, &HF})
            ids.add(New Byte() {&HFF, &H3})
            ids.Add(New Byte() {&H10, &H0})
    
            Dim Results = From id In ids Where id(0) = &H10 And id(1) = &H0
    
            For Each b() As Byte In Results
                MessageBox.Show(b(0).ToString())
            Next
    This will only work if your byte arrays will always have at least two elements.

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2007
    Location
    Latvia (Small country near Baltic Sea)
    Posts
    54

    Re: [2008] How to search in System.Collections.Generic.List?

    lol I'm so stupid...
    I found the fastest way
    ids.Contains(New Byte() {&H10, &H0})


    Anyway thanky you both!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width