|
-
Feb 15th, 2009, 12:39 PM
#1
Thread Starter
Member
[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?
-
Feb 15th, 2009, 12:57 PM
#2
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)
-
Feb 15th, 2009, 12:57 PM
#3
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.
-
Feb 15th, 2009, 01:04 PM
#4
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|