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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Key<br />

IsFixedSize<br />

IsReadOnly<br />

Value<br />

Gets the keys of the HashTable.<br />

Get whether the HashTable is fixed size.<br />

Determines whether the HashTable is read‐only.<br />

Get the values of the HashTable.<br />

The Hashtable uses a similar technique <strong>to</strong> add data <strong>to</strong> its list (with the Add()<br />

method). Once the table has been filled, the keys from the table can be generated<br />

from (using a Hashtable of v):<br />

ICollection keys = v.Keys;<br />

And the values in the list by:<br />

ICollection values = v.Values;<br />

Program 3.10 shows an example of a Hashtable. The same run uses the following<br />

data:<br />

00001,Smith<br />

00010,Bell<br />

00033,McDonald<br />

44444,Mitchel<br />

55555,Martin<br />

43251,Kinlock<br />

Program 3.10: Program3_10_HashTableSimple<br />

namespace ConsoleApplication2<br />

{<br />

using System;<br />

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

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

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

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

class ArrayExample02<br />

{<br />

static void fillData(Hashtable v)<br />

{<br />

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

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

reader.Close();<br />

static void showData(Hashtable v)<br />

Agilent .NET Course: Arrays and Collections 18

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

Saved successfully!

Ooh no, something went wrong!