Use HashSet instead of “seen” Hashtable.

In our code (originally created in .Net 1.1)  there are a few examples of “seen” Hashtable pattern
 
Hashtable seen = new Hashtable();
for (int i = 0; i < nCount; i++)
{
    if (seen[key] == null)
    {
        //Do the changes
        seen.Add(key, key);
    }
}
 
It's better to use type-safe HashSet:
 
HashSet<string> seen = new HashSet<string>();
for (int i = 0; i < nCount; i++)
{
    if (!seen.Contains(key))
    {
        //Do the changes
        seen.Add(key);
    }
}

Advertisements