anass 90 anass 90 - 1 year ago 84
C# Question

Inserting a text file into a hashtable with c#

i have a text file witch contains values like this :


i need to insert this file into a HashTable with c#, this is what i've done so far :

string[] FileLines = File.ReadAllLines(@"D:TestHash.txt");

Hashtable hashtable = new Hashtable();

foreach (string line in FileLines)
// dont know what to do here

and after this i need to match a value from a textbox with the hashtable values. what should i do?

Answer Source

A Hashtable is a container for key-value-pairs. Since you only have values, not key-value-pairs, you don't need a hashtable, you need a HashSet:

HashSet<string> fileLineSet = new HashSet<string>(FileLines);

Check MSDN on how to use a hash set (including an example).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download