<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="IComparer.aspx.vb" Inherits="IComparer" %>

<asp:Content ID="Content1" ContentPlaceHolderID="headerContent" Runat="Server">

    <script language="javascript" type="text/javascript">
// <!CDATA[

        function TextArea1_onclick() {

        }

// ]]>
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="rightColumnContent" Runat="Server">

    <p><a href="http://msdn.microsoft.com/en-us/library/system.icomparable.aspx" target="_blank">IComparable MSDN Library definition</a>  </p>
    <br />
    
    
<textarea id="TextArea1" style="height:800px; width: 1000px;" cols="20" rows="2" onclick="return TextArea1_onclick()">
  <Serializable()> _
  Public Class Car
        Implements IComparable

        Private m_make As String
        Private m_model As String
        Private m_year As Integer
        Private m_color As String

        Public Property Make() As String
            Get
                Return m_make
            End Get
            Set(ByVal value As String)
                value = m_make
            End Set
        End Property

        Public Property Model() As String
            Get
                Return m_model
            End Get
            Set(ByVal value As String)
                value = m_model
            End Set
        End Property

        Public Property Year() As Integer
            Get
                Return m_year
            End Get
            Set(ByVal value As Integer)
                value = m_year
            End Set
        End Property

        Public Property Color() As String
            Get
                Return m_color
            End Get
            Set(ByVal value As String)
                value = m_color
            End Set
        End Property

        Sub New()
            Me.Make = ""
            Me.Model = ""
            Me.Year = 0
            Me.Color = ""
        End Sub

        Sub New(ByVal _make As String, ByVal _model As String, ByVal _year As Integer, ByVal _color As String)
            Me.Make = _make
            Me.Model = _model
            Me.Year = _year
            Me.Color = _color
        End Sub
        Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
            Dim b As Car

            If (TypeOf obj Is Car) Then
                'cast the object to a car object
                b = CType(obj, Car)
            Else
                'throw an exception if the object to compare is not a car object
                Throw New ArgumentException("Object obj is not a Car type")
            End If
            'return 0 if both makes have the same make, 1 if object a is greater then oject b, -1 if object a is less then object 
            Return String.Compare(Me.Make, b.Make)
        End Function
    End Class
</textarea>

<p><a href="http://msdn.microsoft.com/en-us/library/system.collections.icomparer.aspx" target="_blank">IComparer MSDN Library definition </a></p>
<br />

    <textarea id="TextArea2" cols="20" rows="2" style="width: 1000px; height: 500px">
    Public Class CompareCars
        Implements IComparer

        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
            Dim a As Car
            Dim b As Car

            If (TypeOf x Is Car) Then
                'cast the object to a car object
                a = CType(x, Car)
            Else
                'throw an exception if the object to compare is not a car object
                Throw New ArgumentException("Object x is not a Car type")
            End If

            If (TypeOf y Is Car) Then
                b = CType(y, Car)
            Else
                Throw New ArgumentException("Object y is not a Car type")
            End If

            'return 0 if both makes have the same make, 1 if object a is greater then oject b, -1 if object a is less then object
            Return String.Compare(a.Model, b.Model)
        End Function
    End Class
    </textarea>
</asp:Content>


