tags:

views:

232

answers:

3

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

A: 

No they behave exactly the same

Barry
+5  A: 

The Contains method just calls the ContainsKey method internally - you can check this using Reflector.

David M
+8  A: 

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);
}
GvS