<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.vbex.ru/index.php?action=history&amp;feed=atom&amp;title=VB.Net%2FData_Structure%2FCompareTo</id>
		<title>VB.Net/Data Structure/CompareTo - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.vbex.ru/index.php?action=history&amp;feed=atom&amp;title=VB.Net%2FData_Structure%2FCompareTo"/>
		<link rel="alternate" type="text/html" href="http://www.vbex.ru/index.php?title=VB.Net/Data_Structure/CompareTo&amp;action=history"/>
		<updated>2026-04-05T12:26:04Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.vbex.ru/index.php?title=VB.Net/Data_Structure/CompareTo&amp;diff=1034&amp;oldid=prev</id>
		<title> в 16:40, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.vbex.ru/index.php?title=VB.Net/Data_Structure/CompareTo&amp;diff=1034&amp;oldid=prev"/>
				<updated>2010-05-26T16:40:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 16:40, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.vbex.ru/index.php?title=VB.Net/Data_Structure/CompareTo&amp;diff=1035&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.vbex.ru/index.php?title=VB.Net/Data_Structure/CompareTo&amp;diff=1035&amp;oldid=prev"/>
				<updated>2010-05-26T12:45:49Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Define Comparable Object and Sort them==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;vbnet&amp;quot;&amp;gt;&lt;br /&gt;
Imports System&lt;br /&gt;
Public Class MainClass&lt;br /&gt;
  Shared Sub Main()&lt;br /&gt;
    Dim e1 As New Employee(&amp;quot;E1&amp;quot;, 50000)&lt;br /&gt;
    Dim e2 As New Employee(&amp;quot;E2&amp;quot;, 60000)&lt;br /&gt;
    Dim e3 As New Employee(&amp;quot;E3&amp;quot;, 20000)&lt;br /&gt;
    Dim e4 As New Employee(&amp;quot;E4&amp;quot;, 1)&lt;br /&gt;
    Dim theEmployees() As Employee = {e1, e2, e3, e4}&lt;br /&gt;
    &lt;br /&gt;
    Array.Sort(theEmployees) &amp;quot;call the CompareTo &lt;br /&gt;
    &lt;br /&gt;
    Dim aEmployee As Employee&lt;br /&gt;
    For Each aEmployee In theEmployees&lt;br /&gt;
      Console.WriteLine(aEmployee.TheName &amp;amp; &amp;quot; has yearly salary $&amp;quot; &amp;amp; FormatNumber(aEmployee.Salary))&lt;br /&gt;
    Next&lt;br /&gt;
  End Sub&lt;br /&gt;
End Class&lt;br /&gt;
Public Class Employee&lt;br /&gt;
  Implements IComparable&lt;br /&gt;
  Private m_Name As String&lt;br /&gt;
  Private m_Salary As Decimal&lt;br /&gt;
  Public Sub New(ByVal theName As String, ByVal curSalary As Decimal)&lt;br /&gt;
    m_Name = TheName&lt;br /&gt;
    m_Salary = curSalary&lt;br /&gt;
  End Sub&lt;br /&gt;
  Public Function CompareTo(ByVal AnEmployee As Object) As Integer _&lt;br /&gt;
  Implements IComparable.rupareTo&lt;br /&gt;
    If CType(AnEmployee, Employee).Salary &amp;lt; Me.Salary Then&lt;br /&gt;
      Return -1&lt;br /&gt;
    ElseIf CType(AnEmployee, Employee).Salary = Me.Salary Then&lt;br /&gt;
      Return 0&lt;br /&gt;
    ElseIf CType(AnEmployee, Employee).Salary &amp;gt; Me.Salary Then&lt;br /&gt;
      Return 1&lt;br /&gt;
    End If&lt;br /&gt;
  End Function&lt;br /&gt;
  Public ReadOnly Property TheName() As String&lt;br /&gt;
    Get&lt;br /&gt;
      Return m_Name&lt;br /&gt;
    End Get&lt;br /&gt;
  End Property&lt;br /&gt;
  Public ReadOnly Property Salary() As Decimal&lt;br /&gt;
    Get&lt;br /&gt;
      Return MyClass.m_Salary&lt;br /&gt;
    End Get&lt;br /&gt;
  End Property&lt;br /&gt;
End Class&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use IComparer to sort by different properties==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;vbnet&amp;quot;&amp;gt;&lt;br /&gt;
Imports System&lt;br /&gt;
Imports System.Collections&lt;br /&gt;
&lt;br /&gt;
Public Class MainClass&lt;br /&gt;
  Shared Sub Main()&lt;br /&gt;
    Dim e1 As New Employee(&amp;quot;E1&amp;quot;, 50000)&lt;br /&gt;
    Dim e2 As New Employee(&amp;quot;E2&amp;quot;, 60000)&lt;br /&gt;
    Dim e3 As New Employee(&amp;quot;E3&amp;quot;, 20000)&lt;br /&gt;
    Dim e4 As New Employee(&amp;quot;E4&amp;quot;, 1)&lt;br /&gt;
    Dim theEmployees() As Employee = {e1, e2, e3, e4}&lt;br /&gt;
    &lt;br /&gt;
    Array.Sort(theEmployees)&lt;br /&gt;
    &lt;br /&gt;
    Console.WriteLine(&amp;quot;Sort by Salary&amp;quot;)&lt;br /&gt;
    &lt;br /&gt;
    Dim SortingByName As SortByName = New SortByName()&lt;br /&gt;
    Dim aEmployee As Employee&lt;br /&gt;
&lt;br /&gt;
    For Each aEmployee In theEmployees&lt;br /&gt;
      Console.WriteLine(aEmployee.TheName &amp;amp; &amp;quot; has yearly salary $&amp;quot; &amp;amp; FormatNumber(aEmployee.Salary))&lt;br /&gt;
    Next&lt;br /&gt;
    Console.WriteLine(&amp;quot;Sort by Name&amp;quot;)&lt;br /&gt;
    Array.Sort(theEmployees, SortingByName)&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    For Each aEmployee In theEmployees&lt;br /&gt;
      Console.WriteLine(aEmployee.TheName &amp;amp; &amp;quot; has yearly salary $&amp;quot; &amp;amp; FormatNumber(aEmployee.Salary))&lt;br /&gt;
    Next&lt;br /&gt;
  End Sub&lt;br /&gt;
End Class&lt;br /&gt;
&lt;br /&gt;
Public Class SortByName&lt;br /&gt;
  Implements IComparer&lt;br /&gt;
  Public Function CompareTo(ByVal firstEmp As Object, ByVal _&lt;br /&gt;
  secondEmp As Object) As Integer Implements IComparer.rupare&lt;br /&gt;
    Dim temp1 As Employee = CType(firstEmp, Employee)&lt;br /&gt;
    Dim temp2 As Employee = CType(secondEmp, Employee)&lt;br /&gt;
    Return String.rupare(temp1.TheName, temp2.TheName)&lt;br /&gt;
  End Function&lt;br /&gt;
End Class&lt;br /&gt;
Public Class Employee&lt;br /&gt;
  Implements IComparable&lt;br /&gt;
  Private m_Name As String&lt;br /&gt;
  Private m_Salary As Decimal&lt;br /&gt;
  Public Sub New(ByVal theName As String, ByVal curSalary As Decimal)&lt;br /&gt;
    m_Name = theName&lt;br /&gt;
    m_Salary = curSalary&lt;br /&gt;
  End Sub&lt;br /&gt;
  Public Function CompareTo(ByVal AnEmployee As Object) As Integer _&lt;br /&gt;
  Implements IComparable.rupareTo&lt;br /&gt;
    If CType(AnEmployee, Employee).Salary &amp;lt; Me.Salary Then&lt;br /&gt;
      Return -1&lt;br /&gt;
    ElseIf CType(AnEmployee, Employee).Salary = Me.Salary Then&lt;br /&gt;
      Return 0&lt;br /&gt;
    ElseIf CType(AnEmployee, Employee).Salary &amp;gt; Me.Salary Then&lt;br /&gt;
      Return 1&lt;br /&gt;
    End If&lt;br /&gt;
  End Function&lt;br /&gt;
  Public ReadOnly Property TheName() As String&lt;br /&gt;
    Get&lt;br /&gt;
      Return m_Name&lt;br /&gt;
    End Get&lt;br /&gt;
  End Property&lt;br /&gt;
  Public ReadOnly Property Salary() As Decimal&lt;br /&gt;
    Get&lt;br /&gt;
      Return MyClass.m_Salary&lt;br /&gt;
    End Get&lt;br /&gt;
  End Property&lt;br /&gt;
End Class&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>