Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Hashtable - Contains vs ContainsKey

Tags:

.net

hashtable

I just noticed the HashTable objects have a Contains and CotainsKey method, with same description. So are they just synonyms or is there som edifference behind the scenes

like image 944
Midhat Avatar asked Apr 07 '10 08:04

Midhat


1 Answers

If you examine the code of Contains with reflector, you can see that it directly call ContainsKey.

The IL is:

.method public hidebysig newslot virtual instance bool Contains(object key) cil managed
{
    .maxstack 8
    L_0000: ldarg.0 
    L_0001: ldarg.1 
    L_0002: callvirt instance bool System.Collections.Hashtable::ContainsKey(object)
    L_0007: ret 
}

This translates to the following C#

public virtual bool Contains(object key)
{
    return this.ContainsKey(key);
}
like image 86
GvS Avatar answered Sep 21 '22 13:09

GvS