Dim alCustomers as New ArrayList
Dim li1 As New ListItem("John", 7)
alCustomers.Add(li1)
Dim li2 As New ListItem("Abe", 2)
alCustomers.Add(li2)
How can I sort the alCustomers arraylist, by Value?
Abe,2
John,7
Dim alCustomers as New ArrayList
Dim li1 As New ListItem("John", 7)
alCustomers.Add(li1)
Dim li2 As New ListItem("Abe", 2)
alCustomers.Add(li2)
How can I sort the alCustomers arraylist, by Value?
Abe,2
John,7
In C# with .NET 3.5 or newer it would work like this:
// Create a list of ListItem objects
List<ListItem> alCustomers = new List<ListItem>();
// Add the list items
alCustomers.Add(new ListItem("John", 7));
alCustomers.Add(new ListItem("Abe", 2));
var orderedCustomers = alCustomers
// Order the items by their value...
.OrderBy(item => item.Value)
// and convert it to a list.
.ToList();
Unfortunately since the last version of Visual Basic I used was VB6, I am not sure how to translate that. This is my best guess:
// Create a list of ListItem objects
Dim alCustomers as New List(Of ListItem)
// Add the list items
alCustomers.Add(New ListItem("John", 7))
alCustomers.Add(New ListItem("Abe", 2))
Dim orderedCustomers As List(Of ListItem) = alCustomers
// Order the items by their value...
.OrderBy(Function(item As ListItem) item.Value)
// and convert it to a list.
.ToList(Of ListItem)()