countrymeister
asked on
Sort an Arraylist holding an array of a custom class object of Orders
I need to sort an arraylist which holds a array of objects called orders.
Orders has a property called OrderDate and a List Of testCodes.
I want to sort the Araylist in asc OrderDate
here is some code snippet on how the arraylist gets populated
Dim deliveryOrders as New Arraylist
Dim orders as Orders
Dim orders.TestCodes - new List(of testcodes)
order .OrderDate = '3/1/2001'
blah blah blah
deliveryOrders.Add(orders)
Need to sort this deliveryOrders arraylist
Orders has a property called OrderDate and a List Of testCodes.
I want to sort the Araylist in asc OrderDate
here is some code snippet on how the arraylist gets populated
Dim deliveryOrders as New Arraylist
Dim orders as Orders
Dim orders.TestCodes - new List(of testcodes)
order .OrderDate = '3/1/2001'
blah blah blah
deliveryOrders.Add(orders)
Need to sort this deliveryOrders arraylist
Public Class Order
Private _OrderDate As String
Private _Tests As List(Of TestCodes)
Public Property CollectionDate() As String
Get
Return _CollectionDate
End Get
Set(ByVal value As String)
_CollectionDate = value
End Set
End Property
Public Property Tests() As List(Of TestCodes)
Get
Return _Tests
End Get
Set(ByVal value As List(Of TestCodes))
_Tests = value
End Set
End Property
End Class
Public Class TestCodes
Private _TestCode As String
Private _Description As String
Public Property TestCode() As String
Get
Return _TestCode
End Get
Set(ByVal value As String)
_TestCode = value
End Set
End Property
Public Property Description() As String
Get
Return _Description
End Get
Set(ByVal value As String)
_Description = value
End Set
End Property
End Class
But you can use SortedList or a SortedDictionary. They are strong typed classes and it will do what you want.
Dim deliveryOrders As New SortedList(Of Integer, Order)
Dim deliveryOrders As New SortedDictionary(Of Integer, Order)
Dim deliveryOrders As New SortedList(Of Integer, Order)
Dim deliveryOrders As New SortedDictionary(Of Integer, Order)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Have you tried?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Pleaase refund the points as I resolved this issue myself
What was needed was the implementation of the Icomparable and Icomaprer interfaces
What was needed was the implementation of the Icomparable and Icomaprer interfaces
deliveryOrders.Sort()