I have a Hashtable
which has a key of String
and the value as String
, but I've reached a point in my project where I need to be able to store multiple different data types. For example, I'm going to need to store int
, String
, Date
, etc, all in one Hashtable
.
Object Types in HashTables The keys and values in a hash table can have any . NET object type, and a single hash table can have keys and values of multiple types.
The HashTable can be set to store generic Objects as opposed to specific class types, however the type conversion when retrieving them does not happen automatically.
Variables can store data of different types, and different data types can do different things.
You can create an array with elements of different data types when declare the array as Object. Since System. Object is the base class of all other types, an item in an array of Objects can have a reference to any other type of object.
HashTable
or any Collection Map
can handle this, except for int
and other primitive types: you can't store primitive types, only Object
references. int
will need to be wrapped as a Integer
object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With