Hi all, I receive an array of classes from a service that contains properties such as phone and call time. This list could have multiple phone numbers, as calls may be attempted more than once.
I'd like to only have a list with the most recent attempt for each number, or, a list of the most recent item within a group of items contained in an array. Since I can't modify the service, I'll have to do this within VB.
Here's what I was thinking, since I can arrange to have the array sorted by phone asc, calltime desc. Create a different array, and add items to it while looping through the initial array:
Dim someString() as ClassName = FunctionThatReturnsArrayOfClassNames
Dim otherString() as ClassName
For i as Int32 = 0 to someString.length - 1
If Not otherString.Contains(someString(i)) then
'Add
Else
End If
Next
Seems like that would work, but I wondered if this method would be efficient, or if there is a more efficient way? Looks like I'd have to use Redim and Preserve, and I've read that method is inefficient. Or maybe I'm completely wrong, and it won't even
work - about to try right now.
carriehoff
Member
37 Points
32 Posts
Select most recent items from array of classes
May 17, 2012 07:53 PM|LINK
Hi all, I receive an array of classes from a service that contains properties such as phone and call time. This list could have multiple phone numbers, as calls may be attempted more than once.
I'd like to only have a list with the most recent attempt for each number, or, a list of the most recent item within a group of items contained in an array. Since I can't modify the service, I'll have to do this within VB.
Here's what I was thinking, since I can arrange to have the array sorted by phone asc, calltime desc. Create a different array, and add items to it while looping through the initial array:
Dim someString() as ClassName = FunctionThatReturnsArrayOfClassNames Dim otherString() as ClassName For i as Int32 = 0 to someString.length - 1 If Not otherString.Contains(someString(i)) then 'Add Else End If NextSeems like that would work, but I wondered if this method would be efficient, or if there is a more efficient way? Looks like I'd have to use Redim and Preserve, and I've read that method is inefficient. Or maybe I'm completely wrong, and it won't even work - about to try right now.
Thanks for any help,
Carrie