[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?
Re: [2008] How to search in System.Collections.Generic.List?
vb Code:
Private Function MySearchMethod(ByVal b as Byte())
'Code here to read b and determine if it's the one you're looking for
'If it is,
Return True
'else if it isn't
Return False
End Function
Then use:
vb Code:
ids.Find(Addressof MySearchMethod)
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.
Re: [2008] How to search in System.Collections.Generic.List?
lol I'm so stupid...
I found the fastest way :D
ids.Contains(New Byte() {&H10, &H0})
Anyway thanky you both! :)