IComparable : IComparable « Collections « VB.Net Tutorial

VB.Net Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statements
5. Date Time
6. Class Module
7. Development
8. Collections
9. Generics
10. Attributes
11. Event
12. Stream File
13. GUI
14. GUI Applications
15. 2D Graphics
16. I18N Internationlization
17. Reflection
18. Regular Expressions
19. Security
20. Socket Network
21. Thread
22. Windows
23. XML
24. Database ADO.net
25. Design Patterns
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial » Collections » IComparable 
8. 20. 1. IComparable
 
 

Imports System.Collections

Module Test
    Public Sub Main()

        Dim objEmployee1 As New Employee()
        Dim objEmployee2 As New Employee()
        Dim objEmployee3 As New Employee()

        objEmployee1.FirstName = "A"
        objEmployee1.LastName = "B"
        objEmployee2.FirstName = "C"
        objEmployee2.LastName = "D"
        objEmployee3.FirstName = "E"
        objEmployee3.LastName = "F"

        Dim slPeople As New SortedList()

        slPeople.Add(objEmployee1, 1)
        slPeople.Add(objEmployee2, 2)
        slPeople.Add(objEmployee3, 3)

        Dim objDE As DictionaryEntry

        For Each objDE In slPeople
            Console.WriteLine("{0} {1}",CType(objDE.Key, Employee).DisplayName, CType(objDE.Value,Integer))
        Next
    End Sub
End Module

Public Class Employee
    Implements IComparable
    Public FirstName As String
    Public LastName As String

    Public ReadOnly Property DisplayName() As String
        Get
            Return String.Format("{0} {1}", FirstName, LastName)
        End Get
    End Property

    Public Function CompareTo(ByVal obj As ObjectAs Integer _
        Implements System.IComparable.CompareTo

        Dim objOtherEmployee As Employee
        objOtherEmployee = CType(obj, Employee)

        If objOtherEmployee.LastName > Me.LastName Then
            Return -1
        ElseIf objOtherEmployee.LastName < Me.LastName Then
            Return 1
        Else
            If objOtherEmployee.FirstName > Me.FirstName Then
                Return -1
            ElseIf objOtherEmployee.FirstName < Me.FirstName Then
                Return 1
            Else
                Return 0
            End If
        End If
    End Function
End Class

        
  
  




A B 1
C D 2
E F 3

 
8. 20. IComparable
8. 20. 1. IComparable
w_w___w._j___a__v__a_2___s___.__c___o___m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.