Complete set: Intro to C - Bill Buchanan
Complete set: Intro to C - Bill Buchanan
Complete set: Intro to C - Bill Buchanan
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
{<br />
int i;<br />
ICollection keys = v.Keys;<br />
ICollection values = v.Values;<br />
System.Console.WriteLine("Keys are: ");<br />
foreach (string key in keys)<br />
Console.WriteLine("{0}",key);<br />
System.Console.WriteLine("Values are: ");<br />
foreach (string val in values)<br />
Console.WriteLine("{0}",val);<br />
}<br />
static void Main(string[] args)<br />
{<br />
Hashtable Vals = new Hashtable();<br />
}<br />
}<br />
}<br />
fillData(Vals);<br />
showData(Vals);<br />
System.Console.ReadLine();<br />
duction <strong>to</strong> .NET<br />
<strong>Intro</strong><br />
Sample Run 3.10<br />
Keys are:<br />
00001<br />
00010<br />
00033<br />
44444<br />
55555<br />
43251<br />
Values are:<br />
Smith<br />
Bell<br />
McDonald<br />
Mitchel<br />
Martin<br />
Kinlock<br />
It is possible <strong>to</strong> browse through the dictionary by creating an enumera<strong>to</strong>r (using the<br />
GetEnumera<strong>to</strong>r() method). This creates a list of references <strong>to</strong> the elements in the<br />
hashtable. This is achieved with the following (for a hashtable of v):<br />
System.Collections.IDictionaryEnumera<strong>to</strong>r enumera<strong>to</strong>r = v.GetEnumera<strong>to</strong>r();<br />
while (enumera<strong>to</strong>r.MoveNext())<br />
{<br />
Console.WriteLine("{0} {1}",enumera<strong>to</strong>r.Key, enumera<strong>to</strong>r.Value);<br />
}<br />
A complete program is shown in Program 3.11.<br />
Agilent .NET Course: Arrays and Collections 19