CaseInsensitiveHashCodeProvider 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注意
Please use StringComparer instead.
注意
CaseInsensitiveHashCodeProvider has been deprecated. Use StringComparer instead.
使用忽略字符串大小写的哈希算法,为对象提供哈希代码。
public ref class CaseInsensitiveHashCodeProvider : System::Collections::IHashCodeProvider
[System.Obsolete("Please use StringComparer instead.")]
public class CaseInsensitiveHashCodeProvider : System.Collections.IHashCodeProvider
[System.Obsolete("CaseInsensitiveHashCodeProvider has been deprecated. Use StringComparer instead.")]
public class CaseInsensitiveHashCodeProvider : System.Collections.IHashCodeProvider
[System.Serializable]
public class CaseInsensitiveHashCodeProvider : System.Collections.IHashCodeProvider
[System.Obsolete("Please use StringComparer instead.")]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class CaseInsensitiveHashCodeProvider : System.Collections.IHashCodeProvider
[<System.Obsolete("Please use StringComparer instead.")>]
type CaseInsensitiveHashCodeProvider = class
interface IHashCodeProvider
[<System.Obsolete("CaseInsensitiveHashCodeProvider has been deprecated. Use StringComparer instead.")>]
type CaseInsensitiveHashCodeProvider = class
interface IHashCodeProvider
[<System.Serializable>]
type CaseInsensitiveHashCodeProvider = class
interface IHashCodeProvider
[<System.Obsolete("Please use StringComparer instead.")>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type CaseInsensitiveHashCodeProvider = class
interface IHashCodeProvider
Public Class CaseInsensitiveHashCodeProvider
Implements IHashCodeProvider
- 继承
-
CaseInsensitiveHashCodeProvider
- 属性
- 实现
示例
下面的代码示例创建一个区分大小写的哈希表和一个不区分大小写的哈希表,并演示它们的行为差异,即使两者都包含相同的元素。
using namespace System;
using namespace System::Collections;
using namespace System::Globalization;
int main()
{
// Create a Hashtable using the default hash code provider and the default comparer.
Hashtable^ myHT1 = gcnew Hashtable;
myHT1->Add( "FIRST", "Hello" );
myHT1->Add( "SECOND", "World" );
myHT1->Add( "THIRD", "!" );
// Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer,
// based on the culture of the current thread.
Hashtable^ myHT2 = gcnew Hashtable( gcnew CaseInsensitiveHashCodeProvider,gcnew CaseInsensitiveComparer );
myHT2->Add( "FIRST", "Hello" );
myHT2->Add( "SECOND", "World" );
myHT2->Add( "THIRD", "!" );
// Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer,
// based on the InvariantCulture.
Hashtable^ myHT3 = gcnew Hashtable( CaseInsensitiveHashCodeProvider::DefaultInvariant,CaseInsensitiveComparer::DefaultInvariant );
myHT3->Add( "FIRST", "Hello" );
myHT3->Add( "SECOND", "World" );
myHT3->Add( "THIRD", "!" );
// Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer,
// based on the Turkish culture (tr-TR), where "I" is not the uppercase version of "i".
CultureInfo^ myCul = gcnew CultureInfo( "tr-TR" );
Hashtable^ myHT4 = gcnew Hashtable( gcnew CaseInsensitiveHashCodeProvider( myCul ),gcnew CaseInsensitiveComparer( myCul ) );
myHT4->Add( "FIRST", "Hello" );
myHT4->Add( "SECOND", "World" );
myHT4->Add( "THIRD", "!" );
// Search for a key in each hashtable.
Console::WriteLine( "first is in myHT1: {0}", myHT1->ContainsKey( "first" ) );
Console::WriteLine( "first is in myHT2: {0}", myHT2->ContainsKey( "first" ) );
Console::WriteLine( "first is in myHT3: {0}", myHT3->ContainsKey( "first" ) );
Console::WriteLine( "first is in myHT4: {0}", myHT4->ContainsKey( "first" ) );
}
/*
This code produces the following output. Results vary depending on the system's culture settings.
first is in myHT1: False
first is in myHT2: True
first is in myHT3: True
first is in myHT4: False
*/
using System;
using System.Collections;
using System.Globalization;
public class SamplesHashtable {
public static void Main() {
// Create a Hashtable using the default hash code provider and the default comparer.
Hashtable myHT1 = new Hashtable();
myHT1.Add("FIRST", "Hello");
myHT1.Add("SECOND", "World");
myHT1.Add("THIRD", "!");
// Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer,
// based on the culture of the current thread.
Hashtable myHT2 = new Hashtable( new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer() );
myHT2.Add("FIRST", "Hello");
myHT2.Add("SECOND", "World");
myHT2.Add("THIRD", "!");
// Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer,
// based on the InvariantCulture.
Hashtable myHT3 = new Hashtable( CaseInsensitiveHashCodeProvider.DefaultInvariant, CaseInsensitiveComparer.DefaultInvariant );
myHT3.Add("FIRST", "Hello");
myHT3.Add("SECOND", "World");
myHT3.Add("THIRD", "!");
// Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer,
// based on the Turkish culture (tr-TR), where "I" is not the uppercase version of "i".
CultureInfo myCul = new CultureInfo( "tr-TR" );
Hashtable myHT4 = new Hashtable( new CaseInsensitiveHashCodeProvider( myCul ), new CaseInsensitiveComparer( myCul ) );
myHT4.Add("FIRST", "Hello");
myHT4.Add("SECOND", "World");
myHT4.Add("THIRD", "!");
// Search for a key in each hashtable.
Console.WriteLine( "first is in myHT1: {0}", myHT1.ContainsKey( "first" ) );
Console.WriteLine( "first is in myHT2: {0}", myHT2.ContainsKey( "first" ) );
Console.WriteLine( "first is in myHT3: {0}", myHT3.ContainsKey( "first" ) );
Console.WriteLine( "first is in myHT4: {0}", myHT4.ContainsKey( "first" ) );
}
}
/*
This code produces the following output. Results vary depending on the system's culture settings.
first is in myHT1: False
first is in myHT2: True
first is in myHT3: True
first is in myHT4: False
*/
Imports System.Collections
Imports System.Globalization
Public Class SamplesHashtable
Public Shared Sub Main()
' Create a Hashtable using the default hash code provider and the default comparer.
Dim myHT1 As New Hashtable()
myHT1.Add("FIRST", "Hello")
myHT1.Add("SECOND", "World")
myHT1.Add("THIRD", "!")
' Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer,
' based on the culture of the current thread.
Dim myHT2 As New Hashtable(New CaseInsensitiveHashCodeProvider(), New CaseInsensitiveComparer())
myHT2.Add("FIRST", "Hello")
myHT2.Add("SECOND", "World")
myHT2.Add("THIRD", "!")
' Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer,
' based on the InvariantCulture.
Dim myHT3 As New Hashtable(CaseInsensitiveHashCodeProvider.DefaultInvariant, CaseInsensitiveComparer.DefaultInvariant)
myHT3.Add("FIRST", "Hello")
myHT3.Add("SECOND", "World")
myHT3.Add("THIRD", "!")
' Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer,
' based on the Turkish culture (tr-TR), where "I" is not the uppercase version of "i".
Dim myCul As New CultureInfo("tr-TR")
Dim myHT4 As New Hashtable(New CaseInsensitiveHashCodeProvider(myCul), New CaseInsensitiveComparer(myCul))
myHT4.Add("FIRST", "Hello")
myHT4.Add("SECOND", "World")
myHT4.Add("THIRD", "!")
' Search for a key in each hashtable.
Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"))
Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"))
Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"))
Console.WriteLine("first is in myHT4: {0}", myHT4.ContainsKey("first"))
End Sub
End Class
'This code produces the following output. Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: True
'first is in myHT4: False
注解
CaseInsensitiveHashCodeProviderIHashCodeProvider实现接口,该接口支持对字符串不区分大小写的比较,就像实现IComparer支持字符串上不区分大小写比较的接口一样CaseInsensitiveComparer。
重要
不建议使用 CaseInsensitiveHashCodeProvider
类进行新的开发。 相反,我们建议使用 System.StringComparer 、 或 StringComparer.OrdinalIgnoreCase 属性返回的对象StringComparer.CurrentCultureIgnoreCaseStringComparer.InvariantCultureIgnoreCase。
需要由 用作键的对象 Hashtable 来替代 Object.GetHashCode 方法 (或 IHashCodeProvider 接口) ,方法 Object.Equals (或 IComparer 接口) 。 这两种方法或接口的实现必须以相同的方式处理区分大小写:否则, Hashtable 的行为可能不正确。 例如,在创建 时Hashtable,必须将此类与 类或任何不区分大小写IComparer的实现一起使用CaseInsensitiveComparer。
构造函数
CaseInsensitiveHashCodeProvider() |
已过时.
已过时.
使用当前线程的 CaseInsensitiveHashCodeProvider 初始化 CurrentCulture 类的新实例。 |
CaseInsensitiveHashCodeProvider(CultureInfo) |
已过时.
已过时.
使用指定的 CaseInsensitiveHashCodeProvider 初始化 CultureInfo 类的新实例。 |
属性
Default |
已过时.
已过时.
获取 CaseInsensitiveHashCodeProvider 的一个实例,该实例与当前线程的 CurrentCulture 关联并且始终可用。 |
DefaultInvariant |
已过时.
已过时.
获取 CaseInsensitiveHashCodeProvider 的一个实例,该实例与 InvariantCulture 关联并且始终可用。 |
方法
Equals(Object) |
已过时.
已过时.
确定指定对象是否等于当前对象。 (继承自 Object) |
GetHashCode() |
已过时.
已过时.
作为默认哈希函数。 (继承自 Object) |
GetHashCode(Object) |
已过时.
已过时.
使用忽略字符串大小写的哈希算法返回给定对象的哈希代码。 |
GetType() |
已过时.
已过时.
获取当前实例的 Type。 (继承自 Object) |
MemberwiseClone() |
已过时.
已过时.
创建当前 Object 的浅表副本。 (继承自 Object) |
ToString() |
已过时.
已过时.
返回表示当前对象的字符串。 (继承自 Object) |