Trying to sort a arraylist by Objects name
Dim ObjList as new arraylist
Dim TextBox1 as new textbox
Textbox1.name = "CCC"
Dim TextBox2 as new textbox
Textbox1.name = "AAA"
Dim TextBox3 as new textbox
Textbox1.name = "BBB"
ObjList.add(TextBox1)
ObjList.add(TextBox2)
ObjList.add(TextBox3)
ObjList.sort()
Sort creates a error. How would I sort the TextBoxs by Name so it looks like
AAA
BBB
CCC
Thank you
You have to create an
IComparerand pass it to theSortmethod:Or, if you can switch to
List(Of TextBox), an anonymous function (that matches the Comparison(Of T) delegate) will also do: