anass 90 anass 90 - 10 days ago 9
C# Question

Inserting a text file into a hashtable with c#

i have a text file witch contains values like this :

0000000000
0000111222
0000144785


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

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).

Comments