heterogeneous Dictionary

  • Thread starter Thread starter puzzlecracker
  • Start date Start date
P

puzzlecracker

I am looking for a container, custom or not, where I can map
integers to various datatype (int, doubles, strings, etc).


Any suggestions are appreciated.

thanks
 
puzzlecracker,

You could use a Dictionary<int, object>. Mind you, you might have
issues if you are storing value types as values and want to change
fields/properties on those value types, but generally, this is the structure
you want.

You also have to be careful to cast the return value properly when
retreiving the value.
 
puzzlecracker,

    You could use a Dictionary<int, object>.  Mind you, you might have
issues if you are storing value types as values and want to change
fields/properties on those value types, but generally, this is the structure
you want.

    You also have to be careful to cast the return value properly when
retreiving the value.

--
          - Nicholas Paldino [.NET/C# MVP]
          - (e-mail address removed)




I am looking for a container, custom or not,  where I can map
integers to various datatype (int, doubles, strings, etc).
Any suggestions are appreciated.


Thanks, that is exactly what i did after I posted this question. I
wonder if there is a way to avoid casts and make it more type safe.
 
Not really, since you are storing different types. You might want to
consider separate dictionaries for the different types that you are using
(assuming you know the types you will be working with).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

puzzlecracker,

You could use a Dictionary<int, object>. Mind you, you might have
issues if you are storing value types as values and want to change
fields/properties on those value types, but generally, this is the
structure
you want.

You also have to be careful to cast the return value properly when
retreiving the value.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




I am looking for a container, custom or not, where I can map
integers to various datatype (int, doubles, strings, etc).
Any suggestions are appreciated.


Thanks, that is exactly what i did after I posted this question. I
wonder if there is a way to avoid casts and make it more type safe.
 
Back
Top