As the generics were introduced as early as in .NET Framework v.2.0, it made all non-generic collection types like
Hashtable
obsolete. Those types were not marked deprecated in order to avoid breaking compatibility with legacy code, but for new development it makes sense to use only generic types.
Instead of
Hashtable
, you can use the types from
System.Collections.Generic
. You have a choice from
System.Collections.Generic.Dictionary<TKey, TValue>
,
System.Collections.Generic.SortedDictionary<TKey, TValue>
or
System.Collections.Generic.SortedDictionary<TKey, TValue>
, please see:
http://msdn.microsoft.com/en-us/library/xfhwa508.aspx[
^],
http://msdn.microsoft.com/en-us/library/f7fta44c.aspx[
^],
http://msdn.microsoft.com/en-us/library/ms132319.aspx[
^].
They have identical interface, the difference is the difference balance between redundancy in memory consumption and performance.
What else? Ah, looping… Isn't it easy? They all implement the interface
IEnumerable<KeyValuePair<TKey, TValue>>
and it means… what? Right, it means that you can use
foreach
:
foreach (KeyValuePair<TKey, TValue> pair in myCollection) {
TKey key = pair.Key;
TValue value = pair.Value;
}
Now, look at my comment to the question. You did not fully describe required comparison. Let's assume you want to check up if all values are unique or not. Now, remember the properties of dictionary. All key are unique, right. So, you can create yes another dictionary and
use your values as keys. If you add all values as keys to your dictionary, every value is unique is this set.
If you wanted something else (look, you should really look for ambiguities in your questions!) — not a problem: I explained you how to iterate through all members, so you can implement the rest by yourself.
—SA