Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,926 questions

51,859 answers

573 users

How to sort a list of objects in by specific by size in VB.NET

1 Answer

0 votes
Class Test
    Implements IComparable(Of Test)

    Public Sub New(ByVal value As Integer)
        total = value
    End Sub

    Private total As Integer
    Public Property Size() As Integer
        Get
            Return total
        End Get
        Set(ByVal value As Integer)
            total = value
        End Set
    End Property

    Public Function CompareTo(different_object As Test) As Integer _
        Implements IComparable(Of Test).CompareTo
        Return Size().CompareTo(different_object.Size())
    End Function
End Class

Module Module1

    Sub Main()

        Dim list As List(Of Test) = New List(Of Test)

        list.Add(New Test(90))
        list.Add(New Test(20))
        list.Add(New Test(100))
        list.Add(New Test(80))
        list.Add(New Test(31))
        list.Add(New Test(30))

        list.Sort()

        For Each element As Test In list
            Console.WriteLine(element.Size())
        Next

    End Sub

End Module


' run:
' 
' 20
' 30
' 31
' 80
' 90
' 100

 



answered Oct 19, 2018 by avibootz
...