03.01.2015 Views

Complete set: Intro to C - Bill Buchanan

Complete set: Intro to C - Bill Buchanan

Complete set: Intro to C - Bill Buchanan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Program 3.11: Program3_11_HashTableSimpleEnumera<strong>to</strong>r<br />

namespace ConsoleApplication2<br />

{<br />

using System;<br />

using System.Collections; // required for HashTable<br />

using System.IO; // required for File I/O<br />

class ArrayExample02<br />

{<br />

static void fillData(Hashtable v)<br />

{<br />

FileInfo theSourceFile = new FileInfo("..\\..\\test.csv");<br />

StreamReader reader = theSourceFile.OpenText();<br />

string text;<br />

do<br />

{<br />

text=reader.ReadLine();<br />

if (text==null) break;<br />

string[] str = text.Split(',');<br />

v.Add(str[0],str[1]);<br />

} while (text != null);<br />

}<br />

reader.Close();<br />

static void showData(Hashtable v)<br />

{<br />

System.Collections.IDictionaryEnumera<strong>to</strong>r enumera<strong>to</strong>r = v.GetEnumera<strong>to</strong>r();<br />

}<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 />

static void Main(string[] args)<br />

{<br />

Hashtable Vals = new Hashtable();<br />

duction <strong>to</strong> .NET<br />

<strong>Intro</strong><br />

}<br />

}<br />

fillData(Vals);<br />

showData(Vals);<br />

System.Console.ReadLine();<br />

}<br />

Sample Run 3.11<br />

00001 Smith<br />

00010 Bell<br />

00033 McDonald<br />

44444 Mitchel<br />

55555 Martin<br />

43251 Kinlock<br />

Agilent .NET Course: Arrays and Collections 20

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!