Create Hashtable from dictionary with the specified load factor and IEqualityComparer in CSharp
Description
The following code shows how to create Hashtable from dictionary with the specified load factor and IEqualityComparer.
Example
using System;/*from w w w .jav a 2 s . c om*/
using System.Collections;
using System.Globalization;
class myCultureComparer : IEqualityComparer
{
public CaseInsensitiveComparer myComparer;
public myCultureComparer()
{
myComparer = CaseInsensitiveComparer.DefaultInvariant;
}
public myCultureComparer(CultureInfo myCulture)
{
myComparer = new CaseInsensitiveComparer(myCulture);
}
public new bool Equals(object x, object y)
{
if (myComparer.Compare(x, y) == 0)
{
return true;
}
else
{
return false;
}
}
public int GetHashCode(object obj)
{
// Compare the hash code for the lowercase versions of the strings.
return obj.ToString().ToLower().GetHashCode();
}
}
public class SamplesHashtable
{
public static void Main()
{
SortedList mySL = new SortedList();
Hashtable myHT1 = new Hashtable(mySL, (float).8);
Hashtable myHT2 = new Hashtable(mySL, (float).8, new myCultureComparer());
CultureInfo myCul = new CultureInfo("tr-TR");
Hashtable myHT3 = new Hashtable(mySL, (float).8, new myCultureComparer(myCul));
}
}