Example

 using System; using System.Collections; namespace Samples { public class IHashCodeProviderSample { public class MyComparer: IComparer { public int Compare(Object a, Object b) { return ((IComparable)a).CompareTo(b); } } public class MyHashCodeProvider: IHashCodeProvider { public int GetHashCode(Object o) { return o.GetHashCode(); } } public static void Main() { Hashtable ht1 = new Hashtable( CaseInsensitiveHashCodeProvider.Default, new MyComparer()); Hashtable ht2 = new Hashtable(new MyHashCodeProvider(), new MyComparer()); AddEntires(ht1); AddEntires(ht2); DisplayEntires(ht1); DisplayEntires(ht2); } public static void AddEntires(Hashtable ht) { ht.Add("One","damien"); ht.Add("two", "brad"); ht.Add("Three", "mark"); ht.Add("four", "Maire"); ...

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.