在.net1.1中這樣寫
Hashtable htTemp = new Hashtable( new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer() );
到了,.net2.0後提示過期
是以可以像下面這樣寫。
class myCultureComparer : IEqualityComparer
{
#region 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)
{
return obj.ToString().ToLower().GetHashCode();
}
#endregion
}
使用的時候
Hashtable htTemp1 = new Hashtable( new myCultureComparer());
轉載于:https://www.cnblogs.com/luoboqingcai/archive/2006/04/22/382158.html