<< >>


4.4.5.

 

HashTable

 

Hashtable - , . , . Hashtable - , : . - (Keys), (Values) - object, , int, object!

. :

using System;
using System.Collections;
namespace HashtableExample {
class Statistics
{
public Hashtable AbonentList;
public Statistics() {
AbonentList = new Hashtable();
}
}
 
class Abonent {
public string Name;
public int Phone;
public Abonent(string n, int p) {
Name = n;
Phone = p;
}
}
class Class1 {
[STAThread]
static void Main(string[] args) {
Abonent a1 = new Abonent(", 1234567);
Abonent a2 = new Abonent(", 3216547);
Abonent a3 = new Abonent("", 685472);
Abonent a4 = new Abonent(", 1234500);
Abonent a5 = new Abonent("pa", 3245637);
Statistics myStatistics = new Statistics();
myStatistics.AbonentList.Add(a1 .Phone, a1 .Name);
myStatistics.AbonentList.Add(a2.Phone, a2.Name);
myStatistics.AbonentList.Add(a3.Phone, a3.Name);
myStatistics.AbonentList.Add(a4.Phone, a4.Name);
myStatistics.AbonentList.Add(a5.Phone, a5.Name);
Console.WriteLine(myStatistics.AbonentList[685472]);
}
}
}

Main Abonent, Hashtable AbonentList (myStatistics.AbonentList) Values. Phone. , Add() Hashtable : , .

, () (. 134).

. 134. HashTable.

 

ArrayList

 

ArrayList, Hashtable, System.Collections, . . ArrayList 16 - object. ArrayList 32 . .

. .

using System;
using System.Collections;
namespace ClassArrayList {
class Class1 {
[STAThread]
static void Main(string[] args)
{
ArrayList ar = new ArrayList();
ar.Add("A");
ar.Add("AB");
ar.Add("ABC");
ar.Add("ABCD");
ar.Add("ABCDE");
ar.Add("ABCDEF");
ar.Add("ABCDEFG");
ar.Add("ABCDEFGH");
ar.Add("");
ar.Add("");
Console.WriteLine(" :\n");
foreach (object element in ar) {
Console.WriteLine(element);
}
ar.Remove("ABCD");
Console.WriteLine("aee :\n");
foreach (object element in ar) {
Console.WriteLine(element);
}
ar.Insert(6, "XYZ");
Console.WriteLine(" \nHa \n");
foreach (object element in ar) {
Console.WriteLine(element);
}
ar.Clear();
Console.WriteLine("aee :\n");
foreach (object element in ar) {
Console.WriteLine(element);
}
} // end Main()
} // end class
} // end namespace

135.

. 135. ArrayList

135 , ArrayList , object. .

 



<< >>