1. and 2. can be done relatively compact in several variants:
(Will perform various actions on a typed List(Of Integer) and display results in ListBoxN, N = {1, 2, 3})
vb Code:
Private Sub TestLoopingOfTypedLists() Dim MyList As New List(Of Integer) MyList.AddRange(New Integer() {1, 7, 3, 9, 2, 11, 19, 6, 3, 1, 12}) '1. Iteration over a rearrangement MyList.OrderByDescending(Function(n) 20 - n).ToList().ForEach(AddressOf DoSomethingA) '2. Iterate over subsets of a list. MyList.Distinct.ToList.ForEach(AddressOf DoSomethingB) MyList.Where(Function(n) n > 5).ToList.ForEach(AddressOf DoSomethingC) End Sub Private Sub DoSomethingA(ByVal sInteger As Integer) ListBox1.Items.Add(sInteger.ToString) End Sub Private Sub DoSomethingB(ByVal sInteger As Integer) ListBox2.Items.Add(sInteger.ToString) End Sub Private Sub DoSomethingC(ByVal sInteger As Integer) ListBox3.Items.Add(sInteger.ToString) End Sub
Tom




Reply With Quote