ArrayList.Sort() : ArrayList « System.Collections « C# / C Sharp by API






ArrayList.Sort()

  
/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/

// Sort and search an ArrayList. 
 
using System; 
using System.Collections; 
 
public class SortSearchDemo { 
  public static void Main() { 
    // create an array list 
    ArrayList al = new ArrayList(); 
     
    // Add elements to the array list 
    al.Add(55); 
    al.Add(43); 
    al.Add(-4); 
    al.Add(88); 
    al.Add(3); 
    al.Add(19); 
 
    Console.Write("Original contents: "); 
    foreach(int i in al) 
      Console.Write(i + " "); 
    Console.WriteLine("\n"); 
 
    // Sort 
    al.Sort(); 
 
    // Use foreach loop to display the list. 
    Console.Write("Contents after sorting: "); 
    foreach(int i in al) 
      Console.Write(i + " "); 
    Console.WriteLine("\n"); 
 
    Console.WriteLine("Index of 43 is " + 
                      al.BinarySearch(43)); 
  } 
}

   
    
  








Related examples in the same category

1.new ArrayList()
2.new ArrayList(Collection c)
3.ArrayList.Add
4.ArrayList.AddRange
5.ArrayList.BinarySearch
6.ArrayList.Capacity
7.ArrayList.Clear()
8.ArrayList.Clone
9.ArrayList.Contains
10.ArrayList.CopyTo
11.ArrayList.GetEnumerator()
12.ArrayList.GetRange
13.ArrayList.IndexOf
14.ArrayList.Insert
15.ArrayList.InsertRange()
16.ArrayList.IsFixedSize
17.ArrayList.IsReadOnly
18.ArrayList.LastIndexOf
19.ArrayList.Remove
20.ArrayList.RemoveAt
21.ArrayList.RemoveRange
22.ArrayList.Reverse()
23.ArrayList.SetRange
24.ArrayList.Synchronized
25.ArrayList.ToArray
26.ArrayList.ToArray(typeof(T))
27.ArrayList.TrimToSize()