Yes, you can derive from Dictionary and the override the methods you want to
use, performing the cast. This is from MSDN, and shows an example of using
a string type instead of generic object.
Imports System
Imports System.Collections
Public Class ShortStringDictionary
Inherits DictionaryBase
Default Public Property Item(key As [String]) As [String]
Get
Return CType(Dictionary(key), [String])
End Get
Set
Dictionary(key) = value
End Set
End Property
Public ReadOnly Property Keys() As ICollection
Get
Return Dictionary.Keys
End Get
End Property
Public ReadOnly Property Values() As ICollection
Get
Return Dictionary.Values
End Get
End Property
Public Sub Add(key As [String], value As [String])
Dictionary.Add(key, value)
End Sub 'Add
Public Function Contains(key As [String]) As Boolean
Return Dictionary.Contains(key)
End Function 'Contains
Public Sub Remove(key As [String])
Dictionary.Remove(key)
End Sub 'Remove
End Class
Hi,
Is there a way when using a hashtable in VB.NET to add value of a specific
type and retrieve that same value without having to cast it to the
original type?
Thanks
Marty