If i can use keys of different types on an Hashtable object, what's
stopping me from putting all my values on the same Hashtable?
So long as all of the keys are comparable using Equals(), there are no
duplicates across the various types of keys, and you can tell which
type of value you're getting back for a given key... nothing at all.
If i can use keys of different types on an Hashtable object, what's
stopping me from putting all my values on the same Hashtable?
It's inefficient and very difficult to maintain. You are talking about
mixing types of objects in a collection, so your consuming code will
have to test what type of object it has in order to cast it and do
anything useful. More generally, using the old style collections (not
typesafe), you risk finding errors at runtime that the compiler cannot
possibly catch.
That, I think, was the whole point of getting away from object which needs to
be casted to your type (an expensive operation) vs. Generics, where you can
have the equivalent collection such as List<Twhich is strongly typed and
requires no casting. Did I say it was an expensive operation?
Of course, if you are seeking typecast bipolar disorder, then-- whatever
floats yer boat!
Peter
Comment