Create Hashtable class from another dictionary
Imports System
Imports System.Collections
Imports System.Globalization
Public Class myCultureComparer
Implements IEqualityComparer
Dim myComparer As CaseInsensitiveComparer
Public Sub New()
myComparer = CaseInsensitiveComparer.DefaultInvariant
End Sub
Public Sub New(ByVal myCulture As CultureInfo)
myComparer = New CaseInsensitiveComparer(myCulture)
End Sub
Public Function Equals1(ByVal x As Object, ByVal y As Object) _
As Boolean Implements IEqualityComparer.Equals
If (myComparer.Compare(x, y) = 0) Then
Return True
Else
Return False
End If
End Function
Public Function GetHashCode1(ByVal obj As Object) _
As Integer Implements IEqualityComparer.GetHashCode
Return obj.ToString().ToLower().GetHashCode()
End Function
End Class
Public Class SamplesHashtable
Public Shared Sub Main()
Dim mySL As New SortedList()
mySL.Add("FIRST", "Hello")
mySL.Add("SECOND", "World")
mySL.Add("THIRD", "!")
Dim myHT1 As New Hashtable(mySL)
Dim myHT2 As New Hashtable(mySL, New myCultureComparer())
Dim myCul As New CultureInfo("tr-TR")
Dim myHT3 As New Hashtable(mySL, New myCultureComparer(myCul))
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"))
End Sub
End Class
Related examples in the same category