<?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%2FArrayList_object</id>
		<title>Csharp/CSharp Tutorial/Data Structure/ArrayList object - История изменений</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%2FArrayList_object"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Data_Structure/ArrayList_object&amp;action=history"/>
		<updated>2026-04-30T00:52:28Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Data_Structure/ArrayList_object&amp;diff=5501&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/ArrayList_object&amp;diff=5501&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/ArrayList_object&amp;diff=5502&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/ArrayList_object&amp;diff=5502&amp;oldid=prev"/>
				<updated>2010-05-26T12:15:46Z</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;==Add object with IComparable interface implementation to an ArrayList==&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;
 &lt;br /&gt;
// Implement the non-generic IComparable interface. &lt;br /&gt;
class Product : IComparable { &lt;br /&gt;
  string name; &lt;br /&gt;
  double cost; &lt;br /&gt;
  int onhand; &lt;br /&gt;
 &lt;br /&gt;
  public Product(string n, double c, int h) { &lt;br /&gt;
    name = n; &lt;br /&gt;
    cost = c; &lt;br /&gt;
    onhand = h; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public override string ToString() { &lt;br /&gt;
    return &lt;br /&gt;
      String.Format(&amp;quot;{0,-10}Cost: {1,6:C}  On hand: {2}&amp;quot;, &lt;br /&gt;
                    name, cost, onhand); &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Implement the IComparable interface. &lt;br /&gt;
  public int CompareTo(object obj) { &lt;br /&gt;
    Product b; &lt;br /&gt;
    b = (Product) obj; &lt;br /&gt;
    return name.rupareTo(b.name); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
class MainClass { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    ArrayList inv = new ArrayList(); &lt;br /&gt;
     &lt;br /&gt;
    // Add elements to the list &lt;br /&gt;
    inv.Add(new Product(&amp;quot;A&amp;quot;, 5.5, 3)); &lt;br /&gt;
    inv.Add(new Product(&amp;quot;B&amp;quot;, 8.9, 2));    &lt;br /&gt;
    inv.Add(new Product(&amp;quot;C&amp;quot;, 3.0, 4)); &lt;br /&gt;
    inv.Add(new Product(&amp;quot;D&amp;quot;, 1.8, 8)); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Product list before sorting:&amp;quot;); &lt;br /&gt;
    foreach(Product i in inv) { &lt;br /&gt;
      Console.WriteLine(&amp;quot;   &amp;quot; + i); &lt;br /&gt;
    } &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
 &lt;br /&gt;
    // Sort the list. &lt;br /&gt;
    inv.Sort(); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Product list after sorting:&amp;quot;); &lt;br /&gt;
    foreach(Product i in inv) { &lt;br /&gt;
      Console.WriteLine(&amp;quot;   &amp;quot; + 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;Product list before sorting:&lt;br /&gt;
   A         Cost:  $5.50  On hand: 3&lt;br /&gt;
   B         Cost:  $8.90  On hand: 2&lt;br /&gt;
   C         Cost:  $3.00  On hand: 4&lt;br /&gt;
   D         Cost:  $1.80  On hand: 8&lt;br /&gt;
Product list after sorting:&lt;br /&gt;
   A         Cost:  $5.50  On hand: 3&lt;br /&gt;
   B         Cost:  $8.90  On hand: 2&lt;br /&gt;
   C         Cost:  $3.00  On hand: 4&lt;br /&gt;
   D         Cost:  $1.80  On hand: 8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Add reference objects to ArrayList==&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;
using System.Collections.Specialized;&lt;br /&gt;
class MyClass{&lt;br /&gt;
   public string MyName=&amp;quot;&amp;quot;;   &lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  static void Main(string[] args)&lt;br /&gt;
  {&lt;br /&gt;
    ArrayList classList = new ArrayList();&lt;br /&gt;
    classList.AddRange(new MyClass[] { new MyClass(), &lt;br /&gt;
                                           new MyClass(), &lt;br /&gt;
                                           new MyClass()});&lt;br /&gt;
    Console.WriteLine(&amp;quot;Items in List: {0}&amp;quot;, classList.Count);&lt;br /&gt;
    // Print out current values. &lt;br /&gt;
    foreach(MyClass c in classList)&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;MyClass name: {0}&amp;quot;, c.MyName);  &lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Items in List: 3&lt;br /&gt;
MyClass name:&lt;br /&gt;
MyClass name:&lt;br /&gt;
MyClass name:&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Add user-defined object to an ArrayList==&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;
 &lt;br /&gt;
class Product { &lt;br /&gt;
  string name; &lt;br /&gt;
  double cost; &lt;br /&gt;
  int onhand; &lt;br /&gt;
 &lt;br /&gt;
  public Product(string n, double c, int h) { &lt;br /&gt;
    name = n; &lt;br /&gt;
    cost = c; &lt;br /&gt;
    onhand = h; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public override string ToString() { &lt;br /&gt;
    return &lt;br /&gt;
      String.Format(&amp;quot;{0,-10}Cost: {1,6:C}  On hand: {2}&amp;quot;, &lt;br /&gt;
                    name, cost, onhand); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
class MainClass { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    ArrayList inv = new ArrayList(); &lt;br /&gt;
     &lt;br /&gt;
    // Add elements to the list &lt;br /&gt;
    inv.Add(new Product(&amp;quot;A&amp;quot;, 5.9, 3)); &lt;br /&gt;
    inv.Add(new Product(&amp;quot;B&amp;quot;, 8.2, 2));    &lt;br /&gt;
    inv.Add(new Product(&amp;quot;C&amp;quot;, 3.5, 4)); &lt;br /&gt;
    inv.Add(new Product(&amp;quot;D&amp;quot;, 1.8, 8)); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Product list:&amp;quot;); &lt;br /&gt;
    foreach(Product i in inv) { &lt;br /&gt;
      Console.WriteLine(&amp;quot;   &amp;quot; + 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;Product list:&lt;br /&gt;
   A         Cost:  $5.90  On hand: 3&lt;br /&gt;
   B         Cost:  $8.20  On hand: 2&lt;br /&gt;
   C         Cost:  $3.50  On hand: 4&lt;br /&gt;
   D         Cost:  $1.80  On hand: 8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==ArrayList and your own object: Add objects to ArrayList==&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 Employee : IComparable&lt;br /&gt;
{&lt;br /&gt;
  public string Name;&lt;br /&gt;
  public int Number;&lt;br /&gt;
  public Employee(string Name, int Number)&lt;br /&gt;
  {&lt;br /&gt;
    this.Name = Name;&lt;br /&gt;
    this.Number = Number;&lt;br /&gt;
  }&lt;br /&gt;
  public override string ToString()&lt;br /&gt;
  {&lt;br /&gt;
    return &amp;quot;Name is &amp;quot; + Name + &amp;quot;, Number is &amp;quot; + Number;&lt;br /&gt;
  }&lt;br /&gt;
  public int Compare(object lhs, object rhs)&lt;br /&gt;
  {&lt;br /&gt;
    Employee lhsEmployee = (Employee) lhs;&lt;br /&gt;
    Employee rhsEmployee = (Employee) rhs;&lt;br /&gt;
    if (lhsEmployee.Number &amp;lt; rhsEmployee.Number) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    } else if (lhsEmployee.Number &amp;gt; rhsEmployee.Number) {&lt;br /&gt;
      return 1;&lt;br /&gt;
    } else {&lt;br /&gt;
      return 0;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public int CompareTo(object rhs) {&lt;br /&gt;
    return Compare(this, rhs);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void DisplayArrayList(string arrayListName, ArrayList myArrayList) {&lt;br /&gt;
    for (int i = 0; i &amp;lt; myArrayList.Count; i++) {&lt;br /&gt;
      Console.WriteLine(arrayListName + &amp;quot;[&amp;quot; + i + &amp;quot;] = &amp;quot; + myArrayList[i]);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    ArrayList myArrayList = new ArrayList();&lt;br /&gt;
    // add four Employee objects to myArrayList using the Add() method&lt;br /&gt;
    Console.WriteLine(&amp;quot;Adding four Employee objects to myArrayList&amp;quot;);&lt;br /&gt;
    Employee myM = new Employee(&amp;quot;M&amp;quot;, 2001);&lt;br /&gt;
    Employee myB = new Employee(&amp;quot;B&amp;quot;, 2001);&lt;br /&gt;
    Employee myC = new Employee(&amp;quot;C&amp;quot;, 1999);&lt;br /&gt;
    Employee myT = new Employee(&amp;quot;T&amp;quot;, 1979);&lt;br /&gt;
    myArrayList.Add(myM);&lt;br /&gt;
    myArrayList.Add(myB);&lt;br /&gt;
    myArrayList.Add(myC);&lt;br /&gt;
    myArrayList.Add(myT);&lt;br /&gt;
    DisplayArrayList(&amp;quot;myArrayList&amp;quot;, myArrayList);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Adding four Employee objects to myArrayList&lt;br /&gt;
myArrayList[0] = Name is M, Number is 2001&lt;br /&gt;
myArrayList[1] = Name is B, Number is 2001&lt;br /&gt;
myArrayList[2] = Name is C, Number is 1999&lt;br /&gt;
myArrayList[3] = Name is T, Number is 1979&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==ArrayList and your own object: Get an enumerator using the GetEnumerator() method and use it to read the object elements in ArrayList==&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 Employee : IComparable&lt;br /&gt;
{&lt;br /&gt;
  public string Name;&lt;br /&gt;
  public int Number;&lt;br /&gt;
  public Employee(string Name, int Number)&lt;br /&gt;
  {&lt;br /&gt;
    this.Name = Name;&lt;br /&gt;
    this.Number = Number;&lt;br /&gt;
  }&lt;br /&gt;
  public override string ToString()&lt;br /&gt;
  {&lt;br /&gt;
    return &amp;quot;Name is &amp;quot; + Name + &amp;quot;, Number is &amp;quot; + Number;&lt;br /&gt;
  }&lt;br /&gt;
  public int Compare(object lhs, object rhs)&lt;br /&gt;
  {&lt;br /&gt;
    Employee lhsEmployee = (Employee) lhs;&lt;br /&gt;
    Employee rhsEmployee = (Employee) rhs;&lt;br /&gt;
    if (lhsEmployee.Number &amp;lt; rhsEmployee.Number) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    } else if (lhsEmployee.Number &amp;gt; rhsEmployee.Number) {&lt;br /&gt;
      return 1;&lt;br /&gt;
    } else {&lt;br /&gt;
      return 0;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public int CompareTo(object rhs) {&lt;br /&gt;
    return Compare(this, rhs);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void DisplayArrayList(string arrayListName, ArrayList myArrayList) {&lt;br /&gt;
    for (int i = 0; i &amp;lt; myArrayList.Count; i++) {&lt;br /&gt;
      Console.WriteLine(arrayListName + &amp;quot;[&amp;quot; + i + &amp;quot;] = &amp;quot; + myArrayList[i]);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    ArrayList myArrayList = new ArrayList();&lt;br /&gt;
    // add four Employee objects to myArrayList using the Add() method&lt;br /&gt;
    Console.WriteLine(&amp;quot;Adding four Employee objects to myArrayList&amp;quot;);&lt;br /&gt;
    Employee myM = new Employee(&amp;quot;M&amp;quot;, 2001);&lt;br /&gt;
    Employee myB = new Employee(&amp;quot;B&amp;quot;, 2001);&lt;br /&gt;
    Employee myC = new Employee(&amp;quot;C&amp;quot;, 1999);&lt;br /&gt;
    Employee myT = new Employee(&amp;quot;T&amp;quot;, 1979);&lt;br /&gt;
    myArrayList.Add(myM);&lt;br /&gt;
    myArrayList.Add(myB);&lt;br /&gt;
    myArrayList.Add(myC);&lt;br /&gt;
    myArrayList.Add(myT);&lt;br /&gt;
    DisplayArrayList(&amp;quot;myArrayList&amp;quot;, myArrayList);&lt;br /&gt;
    IEnumerator myEnumerator = myArrayList.GetEnumerator();&lt;br /&gt;
    while (myEnumerator.MoveNext())&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;myEnumerator.Current = &amp;quot; + myEnumerator.Current);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Adding four Employee objects to myArrayList&lt;br /&gt;
myArrayList[0] = Name is M, Number is 2001&lt;br /&gt;
myArrayList[1] = Name is B, Number is 2001&lt;br /&gt;
myArrayList[2] = Name is C, Number is 1999&lt;br /&gt;
myArrayList[3] = Name is T, Number is 1979&lt;br /&gt;
myEnumerator.Current = Name is M, Number is 2001&lt;br /&gt;
myEnumerator.Current = Name is B, Number is 2001&lt;br /&gt;
myEnumerator.Current = Name is C, Number is 1999&lt;br /&gt;
myEnumerator.Current = Name is T, Number is 1979&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==ArrayList and your own object: remove an object from ArrayList==&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 Employee : IComparable&lt;br /&gt;
{&lt;br /&gt;
  public string Name;&lt;br /&gt;
  public int Number;&lt;br /&gt;
  public Employee(string Name, int Number)&lt;br /&gt;
  {&lt;br /&gt;
    this.Name = Name;&lt;br /&gt;
    this.Number = Number;&lt;br /&gt;
  }&lt;br /&gt;
  public override string ToString()&lt;br /&gt;
  {&lt;br /&gt;
    return &amp;quot;Name is &amp;quot; + Name + &amp;quot;, Number is &amp;quot; + Number;&lt;br /&gt;
  }&lt;br /&gt;
  public int Compare(object lhs, object rhs)&lt;br /&gt;
  {&lt;br /&gt;
    Employee lhsEmployee = (Employee) lhs;&lt;br /&gt;
    Employee rhsEmployee = (Employee) rhs;&lt;br /&gt;
    if (lhsEmployee.Number &amp;lt; rhsEmployee.Number) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    } else if (lhsEmployee.Number &amp;gt; rhsEmployee.Number) {&lt;br /&gt;
      return 1;&lt;br /&gt;
    } else {&lt;br /&gt;
      return 0;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public int CompareTo(object rhs) {&lt;br /&gt;
    return Compare(this, rhs);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void DisplayArrayList(string arrayListName, ArrayList myArrayList) {&lt;br /&gt;
    for (int i = 0; i &amp;lt; myArrayList.Count; i++) {&lt;br /&gt;
      Console.WriteLine(arrayListName + &amp;quot;[&amp;quot; + i + &amp;quot;] = &amp;quot; + myArrayList[i]);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    ArrayList myArrayList = new ArrayList();&lt;br /&gt;
    // add four Employee objects to myArrayList using the Add() method&lt;br /&gt;
    Console.WriteLine(&amp;quot;Adding four Employee objects to myArrayList&amp;quot;);&lt;br /&gt;
    Employee myM = new Employee(&amp;quot;M&amp;quot;, 2001);&lt;br /&gt;
    Employee myB = new Employee(&amp;quot;B&amp;quot;, 2001);&lt;br /&gt;
    Employee myC = new Employee(&amp;quot;C&amp;quot;, 1999);&lt;br /&gt;
    Employee myT = new Employee(&amp;quot;T&amp;quot;, 1979);&lt;br /&gt;
    myArrayList.Add(myM);&lt;br /&gt;
    myArrayList.Add(myB);&lt;br /&gt;
    myArrayList.Add(myC);&lt;br /&gt;
    myArrayList.Add(myT);&lt;br /&gt;
    DisplayArrayList(&amp;quot;myArrayList&amp;quot;, myArrayList);&lt;br /&gt;
    myArrayList.Remove(myB);&lt;br /&gt;
    DisplayArrayList(&amp;quot;myArrayList&amp;quot;, myArrayList);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Adding four Employee objects to myArrayList&lt;br /&gt;
myArrayList[0] = Name is M, Number is 2001&lt;br /&gt;
myArrayList[1] = Name is B, Number is 2001&lt;br /&gt;
myArrayList[2] = Name is C, Number is 1999&lt;br /&gt;
myArrayList[3] = Name is T, Number is 1979&lt;br /&gt;
myArrayList[0] = Name is M, Number is 2001&lt;br /&gt;
myArrayList[1] = Name is C, Number is 1999&lt;br /&gt;
myArrayList[2] = Name is T, Number is 1979&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==ArrayList and your own object: Use the BinarySearch() method to search myArrayList for an object==&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 Employee : IComparable&lt;br /&gt;
{&lt;br /&gt;
  public string Name;&lt;br /&gt;
  public int Number;&lt;br /&gt;
  public Employee(string Name, int Number)&lt;br /&gt;
  {&lt;br /&gt;
    this.Name = Name;&lt;br /&gt;
    this.Number = Number;&lt;br /&gt;
  }&lt;br /&gt;
  public override string ToString()&lt;br /&gt;
  {&lt;br /&gt;
    return &amp;quot;Name is &amp;quot; + Name + &amp;quot;, Number is &amp;quot; + Number;&lt;br /&gt;
  }&lt;br /&gt;
  public int Compare(object lhs, object rhs)&lt;br /&gt;
  {&lt;br /&gt;
    Employee lhsEmployee = (Employee) lhs;&lt;br /&gt;
    Employee rhsEmployee = (Employee) rhs;&lt;br /&gt;
    if (lhsEmployee.Number &amp;lt; rhsEmployee.Number) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    } else if (lhsEmployee.Number &amp;gt; rhsEmployee.Number) {&lt;br /&gt;
      return 1;&lt;br /&gt;
    } else {&lt;br /&gt;
      return 0;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public int CompareTo(object rhs) {&lt;br /&gt;
    return Compare(this, rhs);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void DisplayArrayList(string arrayListName, ArrayList myArrayList) {&lt;br /&gt;
    for (int i = 0; i &amp;lt; myArrayList.Count; i++) {&lt;br /&gt;
      Console.WriteLine(arrayListName + &amp;quot;[&amp;quot; + i + &amp;quot;] = &amp;quot; + myArrayList[i]);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    ArrayList myArrayList = new ArrayList();&lt;br /&gt;
    // add four Employee objects to myArrayList using the Add() method&lt;br /&gt;
    Console.WriteLine(&amp;quot;Adding four Employee objects to myArrayList&amp;quot;);&lt;br /&gt;
    Employee myM = new Employee(&amp;quot;M&amp;quot;, 2001);&lt;br /&gt;
    Employee myB = new Employee(&amp;quot;B&amp;quot;, 2001);&lt;br /&gt;
    Employee myC = new Employee(&amp;quot;C&amp;quot;, 1999);&lt;br /&gt;
    Employee myT = new Employee(&amp;quot;T&amp;quot;, 1979);&lt;br /&gt;
    myArrayList.Add(myM);&lt;br /&gt;
    myArrayList.Add(myB);&lt;br /&gt;
    myArrayList.Add(myC);&lt;br /&gt;
    myArrayList.Add(myT);&lt;br /&gt;
    DisplayArrayList(&amp;quot;myArrayList&amp;quot;, myArrayList);&lt;br /&gt;
    myArrayList.Sort();&lt;br /&gt;
    DisplayArrayList(&amp;quot;myArrayList&amp;quot;, myArrayList);&lt;br /&gt;
    int index2 = myArrayList.BinarySearch(myC);&lt;br /&gt;
    Console.WriteLine(&amp;quot;Found myC at index &amp;quot; + index2);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Adding four Employee objects to myArrayList&lt;br /&gt;
myArrayList[0] = Name is M, Number is 2001&lt;br /&gt;
myArrayList[1] = Name is B, Number is 2001&lt;br /&gt;
myArrayList[2] = Name is C, Number is 1999&lt;br /&gt;
myArrayList[3] = Name is T, Number is 1979&lt;br /&gt;
myArrayList[0] = Name is T, Number is 1979&lt;br /&gt;
myArrayList[1] = Name is C, Number is 1999&lt;br /&gt;
myArrayList[2] = Name is M, Number is 2001&lt;br /&gt;
myArrayList[3] = Name is B, Number is 2001&lt;br /&gt;
Found myC at index 1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==ArrayList and your own object: Use the Contains() method to determine if an object is in the ArrayList==&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 Employee : IComparable&lt;br /&gt;
{&lt;br /&gt;
  public string Name;&lt;br /&gt;
  public int Number;&lt;br /&gt;
  public Employee(string Name, int Number)&lt;br /&gt;
  {&lt;br /&gt;
    this.Name = Name;&lt;br /&gt;
    this.Number = Number;&lt;br /&gt;
  }&lt;br /&gt;
  public override string ToString()&lt;br /&gt;
  {&lt;br /&gt;
    return &amp;quot;Name is &amp;quot; + Name + &amp;quot;, Number is &amp;quot; + Number;&lt;br /&gt;
  }&lt;br /&gt;
  public int Compare(object lhs, object rhs)&lt;br /&gt;
  {&lt;br /&gt;
    Employee lhsEmployee = (Employee) lhs;&lt;br /&gt;
    Employee rhsEmployee = (Employee) rhs;&lt;br /&gt;
    if (lhsEmployee.Number &amp;lt; rhsEmployee.Number) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    } else if (lhsEmployee.Number &amp;gt; rhsEmployee.Number) {&lt;br /&gt;
      return 1;&lt;br /&gt;
    } else {&lt;br /&gt;
      return 0;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public int CompareTo(object rhs) {&lt;br /&gt;
    return Compare(this, rhs);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void DisplayArrayList(string arrayListName, ArrayList myArrayList) {&lt;br /&gt;
    for (int i = 0; i &amp;lt; myArrayList.Count; i++) {&lt;br /&gt;
      Console.WriteLine(arrayListName + &amp;quot;[&amp;quot; + i + &amp;quot;] = &amp;quot; + myArrayList[i]);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    ArrayList myArrayList = new ArrayList();&lt;br /&gt;
    // add four Employee objects to myArrayList using the Add() method&lt;br /&gt;
    Console.WriteLine(&amp;quot;Adding four Employee objects to myArrayList&amp;quot;);&lt;br /&gt;
    Employee myM = new Employee(&amp;quot;M&amp;quot;, 2001);&lt;br /&gt;
    Employee myB = new Employee(&amp;quot;B&amp;quot;, 2001);&lt;br /&gt;
    Employee myC = new Employee(&amp;quot;C&amp;quot;, 1999);&lt;br /&gt;
    Employee myT = new Employee(&amp;quot;T&amp;quot;, 1979);&lt;br /&gt;
    myArrayList.Add(myM);&lt;br /&gt;
    myArrayList.Add(myB);&lt;br /&gt;
    myArrayList.Add(myC);&lt;br /&gt;
    myArrayList.Add(myT);&lt;br /&gt;
    DisplayArrayList(&amp;quot;myArrayList&amp;quot;, myArrayList);&lt;br /&gt;
    if (myArrayList.Contains(myB))&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;myArrayList does contain myB&amp;quot;);&lt;br /&gt;
      int index = myArrayList.IndexOf(myB);&lt;br /&gt;
      Console.WriteLine(&amp;quot;myB occurs at index &amp;quot; + index);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Adding four Employee objects to myArrayList&lt;br /&gt;
myArrayList[0] = Name is M, Number is 2001&lt;br /&gt;
myArrayList[1] = Name is B, Number is 2001&lt;br /&gt;
myArrayList[2] = Name is C, Number is 1999&lt;br /&gt;
myArrayList[3] = Name is T, Number is 1979&lt;br /&gt;
myArrayList does contain myB&lt;br /&gt;
myB occurs at index 1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==ArrayList and your own object: Use the GetRange() method to get a range of object elements from ArrayList==&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 Employee : IComparable&lt;br /&gt;
{&lt;br /&gt;
  public string Name;&lt;br /&gt;
  public int Number;&lt;br /&gt;
  public Employee(string Name, int Number)&lt;br /&gt;
  {&lt;br /&gt;
    this.Name = Name;&lt;br /&gt;
    this.Number = Number;&lt;br /&gt;
  }&lt;br /&gt;
  public override string ToString()&lt;br /&gt;
  {&lt;br /&gt;
    return &amp;quot;Name is &amp;quot; + Name + &amp;quot;, Number is &amp;quot; + Number;&lt;br /&gt;
  }&lt;br /&gt;
  public int Compare(object lhs, object rhs)&lt;br /&gt;
  {&lt;br /&gt;
    Employee lhsEmployee = (Employee) lhs;&lt;br /&gt;
    Employee rhsEmployee = (Employee) rhs;&lt;br /&gt;
    if (lhsEmployee.Number &amp;lt; rhsEmployee.Number) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    } else if (lhsEmployee.Number &amp;gt; rhsEmployee.Number) {&lt;br /&gt;
      return 1;&lt;br /&gt;
    } else {&lt;br /&gt;
      return 0;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public int CompareTo(object rhs) {&lt;br /&gt;
    return Compare(this, rhs);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void DisplayArrayList(string arrayListName, ArrayList myArrayList) {&lt;br /&gt;
    for (int i = 0; i &amp;lt; myArrayList.Count; i++) {&lt;br /&gt;
      Console.WriteLine(arrayListName + &amp;quot;[&amp;quot; + i + &amp;quot;] = &amp;quot; + myArrayList[i]);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    ArrayList myArrayList = new ArrayList();&lt;br /&gt;
    // add four Employee objects to myArrayList using the Add() method&lt;br /&gt;
    Console.WriteLine(&amp;quot;Adding four Employee objects to myArrayList&amp;quot;);&lt;br /&gt;
    Employee myM = new Employee(&amp;quot;M&amp;quot;, 2001);&lt;br /&gt;
    Employee myB = new Employee(&amp;quot;B&amp;quot;, 2001);&lt;br /&gt;
    Employee myC = new Employee(&amp;quot;C&amp;quot;, 1999);&lt;br /&gt;
    Employee myT = new Employee(&amp;quot;T&amp;quot;, 1979);&lt;br /&gt;
    myArrayList.Add(myM);&lt;br /&gt;
    myArrayList.Add(myB);&lt;br /&gt;
    myArrayList.Add(myC);&lt;br /&gt;
    myArrayList.Add(myT);&lt;br /&gt;
    DisplayArrayList(&amp;quot;myArrayList&amp;quot;, myArrayList);&lt;br /&gt;
    ArrayList anotherArrayList = myArrayList.GetRange(1, 2);&lt;br /&gt;
    DisplayArrayList(&amp;quot;anotherArrayList&amp;quot;, anotherArrayList);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Adding four Employee objects to myArrayList&lt;br /&gt;
myArrayList[0] = Name is M, Number is 2001&lt;br /&gt;
myArrayList[1] = Name is B, Number is 2001&lt;br /&gt;
myArrayList[2] = Name is C, Number is 1999&lt;br /&gt;
myArrayList[3] = Name is T, Number is 1979&lt;br /&gt;
anotherArrayList[0] = Name is B, Number is 2001&lt;br /&gt;
anotherArrayList[1] = Name is C, Number is 1999&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==ArrayList and your own object: use the IndexOf() method to display the index of an object==&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 Employee : IComparable&lt;br /&gt;
{&lt;br /&gt;
  public string Name;&lt;br /&gt;
  public int Number;&lt;br /&gt;
  public Employee(string Name, int Number)&lt;br /&gt;
  {&lt;br /&gt;
    this.Name = Name;&lt;br /&gt;
    this.Number = Number;&lt;br /&gt;
  }&lt;br /&gt;
  public override string ToString()&lt;br /&gt;
  {&lt;br /&gt;
    return &amp;quot;Name is &amp;quot; + Name + &amp;quot;, Number is &amp;quot; + Number;&lt;br /&gt;
  }&lt;br /&gt;
  public int Compare(object lhs, object rhs)&lt;br /&gt;
  {&lt;br /&gt;
    Employee lhsEmployee = (Employee) lhs;&lt;br /&gt;
    Employee rhsEmployee = (Employee) rhs;&lt;br /&gt;
    if (lhsEmployee.Number &amp;lt; rhsEmployee.Number) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    } else if (lhsEmployee.Number &amp;gt; rhsEmployee.Number) {&lt;br /&gt;
      return 1;&lt;br /&gt;
    } else {&lt;br /&gt;
      return 0;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public int CompareTo(object rhs) {&lt;br /&gt;
    return Compare(this, rhs);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void DisplayArrayList(string arrayListName, ArrayList myArrayList) {&lt;br /&gt;
    for (int i = 0; i &amp;lt; myArrayList.Count; i++) {&lt;br /&gt;
      Console.WriteLine(arrayListName + &amp;quot;[&amp;quot; + i + &amp;quot;] = &amp;quot; + myArrayList[i]);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    ArrayList myArrayList = new ArrayList();&lt;br /&gt;
    // add four Employee objects to myArrayList using the Add() method&lt;br /&gt;
    Console.WriteLine(&amp;quot;Adding four Employee objects to myArrayList&amp;quot;);&lt;br /&gt;
    Employee myM = new Employee(&amp;quot;M&amp;quot;, 2001);&lt;br /&gt;
    Employee myB = new Employee(&amp;quot;B&amp;quot;, 2001);&lt;br /&gt;
    Employee myC = new Employee(&amp;quot;C&amp;quot;, 1999);&lt;br /&gt;
    Employee myT = new Employee(&amp;quot;T&amp;quot;, 1979);&lt;br /&gt;
    myArrayList.Add(myM);&lt;br /&gt;
    myArrayList.Add(myB);&lt;br /&gt;
    myArrayList.Add(myC);&lt;br /&gt;
    myArrayList.Add(myT);&lt;br /&gt;
    DisplayArrayList(&amp;quot;myArrayList&amp;quot;, myArrayList);&lt;br /&gt;
    if (myArrayList.Contains(myB))&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;myArrayList does contain myB&amp;quot;);&lt;br /&gt;
      int index = myArrayList.IndexOf(myB);&lt;br /&gt;
      Console.WriteLine(&amp;quot;myB occurs at index &amp;quot; + index);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Adding four Employee objects to myArrayList&lt;br /&gt;
myArrayList[0] = Name is M, Number is 2001&lt;br /&gt;
myArrayList[1] = Name is B, Number is 2001&lt;br /&gt;
myArrayList[2] = Name is C, Number is 1999&lt;br /&gt;
myArrayList[3] = Name is T, Number is 1979&lt;br /&gt;
myArrayList does contain myB&lt;br /&gt;
myB occurs at index 1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==ArrayList and your own object: Use the Sort() method to sort objects in the ArrayList==&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 Employee : IComparable&lt;br /&gt;
{&lt;br /&gt;
  public string Name;&lt;br /&gt;
  public int Number;&lt;br /&gt;
  public Employee(string Name, int Number)&lt;br /&gt;
  {&lt;br /&gt;
    this.Name = Name;&lt;br /&gt;
    this.Number = Number;&lt;br /&gt;
  }&lt;br /&gt;
  public override string ToString()&lt;br /&gt;
  {&lt;br /&gt;
    return &amp;quot;Name is &amp;quot; + Name + &amp;quot;, Number is &amp;quot; + Number;&lt;br /&gt;
  }&lt;br /&gt;
  public int Compare(object lhs, object rhs)&lt;br /&gt;
  {&lt;br /&gt;
    Employee lhsEmployee = (Employee) lhs;&lt;br /&gt;
    Employee rhsEmployee = (Employee) rhs;&lt;br /&gt;
    if (lhsEmployee.Number &amp;lt; rhsEmployee.Number) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    } else if (lhsEmployee.Number &amp;gt; rhsEmployee.Number) {&lt;br /&gt;
      return 1;&lt;br /&gt;
    } else {&lt;br /&gt;
      return 0;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public int CompareTo(object rhs) {&lt;br /&gt;
    return Compare(this, rhs);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void DisplayArrayList(string arrayListName, ArrayList myArrayList) {&lt;br /&gt;
    for (int i = 0; i &amp;lt; myArrayList.Count; i++) {&lt;br /&gt;
      Console.WriteLine(arrayListName + &amp;quot;[&amp;quot; + i + &amp;quot;] = &amp;quot; + myArrayList[i]);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    ArrayList myArrayList = new ArrayList();&lt;br /&gt;
    // add four Employee objects to myArrayList using the Add() method&lt;br /&gt;
    Console.WriteLine(&amp;quot;Adding four Employee objects to myArrayList&amp;quot;);&lt;br /&gt;
    Employee myM = new Employee(&amp;quot;M&amp;quot;, 2001);&lt;br /&gt;
    Employee myB = new Employee(&amp;quot;B&amp;quot;, 2001);&lt;br /&gt;
    Employee myC = new Employee(&amp;quot;C&amp;quot;, 1999);&lt;br /&gt;
    Employee myT = new Employee(&amp;quot;T&amp;quot;, 1979);&lt;br /&gt;
    myArrayList.Add(myM);&lt;br /&gt;
    myArrayList.Add(myB);&lt;br /&gt;
    myArrayList.Add(myC);&lt;br /&gt;
    myArrayList.Add(myT);&lt;br /&gt;
    DisplayArrayList(&amp;quot;myArrayList&amp;quot;, myArrayList);&lt;br /&gt;
    myArrayList.Sort();&lt;br /&gt;
    DisplayArrayList(&amp;quot;myArrayList&amp;quot;, myArrayList);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Adding four Employee objects to myArrayList&lt;br /&gt;
myArrayList[0] = Name is M, Number is 2001&lt;br /&gt;
myArrayList[1] = Name is B, Number is 2001&lt;br /&gt;
myArrayList[2] = Name is C, Number is 1999&lt;br /&gt;
myArrayList[3] = Name is T, Number is 1979&lt;br /&gt;
myArrayList[0] = Name is T, Number is 1979&lt;br /&gt;
myArrayList[1] = Name is C, Number is 1999&lt;br /&gt;
myArrayList[2] = Name is M, Number is 2001&lt;br /&gt;
myArrayList[3] = Name is B, Number is 2001&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>