<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FData_Structure%2FArray_Sort</id>
		<title>Csharp/CSharp Tutorial/Data Structure/Array Sort - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FData_Structure%2FArray_Sort"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Data_Structure/Array_Sort&amp;action=history"/>
		<updated>2026-04-30T07:45:03Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Data_Structure/Array_Sort&amp;diff=5551&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Data_Structure/Array_Sort&amp;diff=5551&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:53Z</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;Версия 15:31, 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://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Data_Structure/Array_Sort&amp;diff=5552&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Data_Structure/Array_Sort&amp;diff=5552&amp;oldid=prev"/>
				<updated>2010-05-26T12:15:53Z</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;==Display the contents of the sorted array==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
            // Create a new array and populate it.&lt;br /&gt;
            int[] array = { 4, 2, 9, 3 };&lt;br /&gt;
            // Sort the array.&lt;br /&gt;
            Array.Sort(array);&lt;br /&gt;
            foreach (int i in array) { &lt;br /&gt;
                Console.WriteLine(i); &lt;br /&gt;
            }&lt;br /&gt;
    &lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;2&lt;br /&gt;
3&lt;br /&gt;
4&lt;br /&gt;
9&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Implementing IComparable and sort by Array.Sort==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
public class Employee: IComparable{&lt;br /&gt;
    public Employee(string name, int id)&lt;br /&gt;
    {&lt;br /&gt;
        this.name = name;&lt;br /&gt;
        this.id = id;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int IComparable.rupareTo(object obj)&lt;br /&gt;
    {&lt;br /&gt;
        Employee emp2 = (Employee) obj;&lt;br /&gt;
        if (this.id &amp;gt; emp2.id)&lt;br /&gt;
            return(1);&lt;br /&gt;
        if (this.id &amp;lt; emp2.id)&lt;br /&gt;
            return(-1);&lt;br /&gt;
        else&lt;br /&gt;
            return(0);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public override string ToString()&lt;br /&gt;
    {&lt;br /&gt;
        return(String.Format(&amp;quot;{0}:{1}&amp;quot;, name, id));&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    string name;&lt;br /&gt;
    int id;&lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        Employee[] arr = new Employee[4];&lt;br /&gt;
        arr[0] = new Employee(&amp;quot;A&amp;quot;, 1);&lt;br /&gt;
        arr[1] = new Employee(&amp;quot;B&amp;quot;, 2);&lt;br /&gt;
        arr[2] = new Employee(&amp;quot;C&amp;quot;, 4);&lt;br /&gt;
        arr[3] = new Employee(&amp;quot;D&amp;quot;, 3);&lt;br /&gt;
        &lt;br /&gt;
        Array.Sort(arr);&lt;br /&gt;
        foreach (Employee emp in arr)&lt;br /&gt;
            Console.WriteLine(&amp;quot;Employee: {0}&amp;quot;, emp);&lt;br /&gt;
        &lt;br /&gt;
        Console.WriteLine(&amp;quot;Find employee id 2 in the list&amp;quot;);&lt;br /&gt;
        &lt;br /&gt;
        Employee employeeToFind = new Employee(null, 2);&lt;br /&gt;
        int index = Array.BinarySearch(arr, employeeToFind);&lt;br /&gt;
        if (index != -1)&lt;br /&gt;
            Console.WriteLine(&amp;quot;Found: {0}&amp;quot;, arr[index]);    &lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Employee: A:1&lt;br /&gt;
Employee: B:2&lt;br /&gt;
Employee: D:3&lt;br /&gt;
Employee: C:4&lt;br /&gt;
Find employee id 2 in the list&lt;br /&gt;
Found: B:2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Sort an array==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;  &lt;br /&gt;
  &lt;br /&gt;
class MainClass {     &lt;br /&gt;
  public static void Main() {     &lt;br /&gt;
    int[] nums = { 5, 4, 6, 3, 14, 9, 8, 17, 1, 24, -1, 0 }; &lt;br /&gt;
   &lt;br /&gt;
    Console.Write(&amp;quot;Original order: &amp;quot;); &lt;br /&gt;
    foreach(int i in nums)  &lt;br /&gt;
      Console.Write(i + &amp;quot; &amp;quot;); &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
 &lt;br /&gt;
    Array.Sort(nums); &lt;br /&gt;
 &lt;br /&gt;
    Console.Write(&amp;quot;Sorted order:   &amp;quot;); &lt;br /&gt;
    foreach(int i in nums)  &lt;br /&gt;
      Console.Write(i + &amp;quot; &amp;quot;); &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
  }     &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Original order: 5 4 6 3 14 9 8 17 1 24 -1 0&lt;br /&gt;
Sorted order:   -1 0 1 3 4 5 6 8 9 14 17 24&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Sort an array and search for a value==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;  &lt;br /&gt;
  &lt;br /&gt;
class MainClass {     &lt;br /&gt;
  public static void Main() {     &lt;br /&gt;
    int[] nums = { 5, 4, 6, 3, 14, 9, 8, 17, 1, 24, -1, 0 }; &lt;br /&gt;
   &lt;br /&gt;
    Array.Sort(nums); &lt;br /&gt;
 &lt;br /&gt;
     // Search for 14. &lt;br /&gt;
    int idx = Array.BinarySearch(nums, 14); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Index of 14 is &amp;quot; + idx); &lt;br /&gt;
  }     &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Index of 14 is 9&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use Array.Sort to sort object array==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Text;&lt;br /&gt;
class MyClass : IComparable                    &lt;br /&gt;
{&lt;br /&gt;
   public int TheValue;&lt;br /&gt;
   public int CompareTo(object obj)            &lt;br /&gt;
   {&lt;br /&gt;
      MyClass mc = (MyClass)obj;&lt;br /&gt;
      &lt;br /&gt;
      if (this.TheValue &amp;lt; mc.TheValue) &lt;br /&gt;
         return -1;&lt;br /&gt;
      &lt;br /&gt;
      if (this.TheValue &amp;gt; mc.TheValue) &lt;br /&gt;
         return 1;&lt;br /&gt;
      &lt;br /&gt;
      return 0;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
      MyClass[] objectArray = new MyClass[5];         &lt;br /&gt;
      for (int i = 0; i &amp;lt; 5; i++)              &lt;br /&gt;
      {&lt;br /&gt;
         objectArray[i] = new MyClass();&lt;br /&gt;
         objectArray[i].TheValue = 100 - i;&lt;br /&gt;
      }&lt;br /&gt;
      foreach (MyClass i in objectArray)&lt;br /&gt;
         Console.Write(&amp;quot;{0} &amp;quot;, i.TheValue);&lt;br /&gt;
      Array.Sort(objectArray);                        &lt;br /&gt;
      foreach (MyClass i in objectArray)&lt;br /&gt;
         Console.Write(&amp;quot;{0} &amp;quot;, i.TheValue);&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;100 99 98 97 96 96 97 98 99 100&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use System.Array.Sort() to sort an int array==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        int[] arr = {5, 1, 10, 33, 100, 4};&lt;br /&gt;
        Array.Sort(arr);&lt;br /&gt;
        foreach (int v in arr)&lt;br /&gt;
           Console.WriteLine(&amp;quot;Element: {0}&amp;quot;, v);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Element: 1&lt;br /&gt;
Element: 4&lt;br /&gt;
Element: 5&lt;br /&gt;
Element: 10&lt;br /&gt;
Element: 33&lt;br /&gt;
Element: 100&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use the Sort() method to sort the elements in an int array==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    int[] intArray = {5, 2, 3, 1, 6, 9, 7, 14, 25};&lt;br /&gt;
    Array.Sort(intArray);&lt;br /&gt;
    Console.WriteLine(&amp;quot;Sorted intArray:&amp;quot;);&lt;br /&gt;
    for (int i = 0; i &amp;lt; intArray.Length; i++)&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;intArray[&amp;quot; + i + &amp;quot;] = &amp;quot; +&lt;br /&gt;
        intArray[i]);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Sorted intArray:&lt;br /&gt;
intArray[0] = 1&lt;br /&gt;
intArray[1] = 2&lt;br /&gt;
intArray[2] = 3&lt;br /&gt;
intArray[3] = 5&lt;br /&gt;
intArray[4] = 6&lt;br /&gt;
intArray[5] = 7&lt;br /&gt;
intArray[6] = 9&lt;br /&gt;
intArray[7] = 14&lt;br /&gt;
intArray[8] = 25&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>