Code to add entries to the hashtable:
Hashtable hashtable = new Hashtable(new EqualityComparer());
string[] fileLines = File.ReadAllLines(@"somePath");
foreach (var fileLine in fileLines)
{
int indexOfSpace = fileLine.IndexOf(' ');
int indexOfSlash = fileLine.IndexOf('/');
string keyString = fileLine.Remove(indexOfSpace);
string firstValue =
fileLine.Substring(indexOfSpace, indexOfSlash - indexOfSpace - 1);
string secondValue = fileLine.Substring(indexOfSlash + 1);
hashtable.Add(new Key(keyString), firstValue);
hashtable.Add(new Key(keyString), secondValue);
}
Key class to wrap same string:
public class Key
{
private readonly string s;
public Key(string s)
{
this.s = s;
}
public string KeyString
{
get { return s; }
}
}
Equality comparer that supplies GetHashCode functionality in order to make two keys based on same string go to the same entry in hashtable:
public class EqualityComparer : IEqualityComparer
{
public bool Equals(object x, object y)
{
return ReferenceEquals(x, y);
}
public int GetHashCode(object obj)
{
return ((Key) obj).KeyString.GetHashCode();
}
}