First of all, a list (List<T>
) does not have “keys”. However, a Dictionary<TKey, TValue>
does.
Secondly, to answer your performance question: no, there is actually a performance penalty in computing that hash. However, before you jump to the conclusion that it is unnecessary, examine the surrounding code and think about whether the author may have actually needed the MD5 hashsum and not the string itself?
Thirdly, if you need to look something up efficiently, you can use a HashSet<T>
if you just need to check its existence, or Dictionary<TKey, TValue>
if you need to associate the keys that you look up with a value.
If you place strings in a dictionary or hashset, C# will already generate a hash value from any string you put in. This generally uses a hash algorithm that is much faster than MD5.