How to insert an item into a key/value pair object?

Posted by Clay on Stack Overflow See other posts from Stack Overflow or by Clay
Published on 2010-04-30T14:48:26Z Indexed on 2010/04/30 15:07 UTC
Read the original article Hit count: 159

Filed under:
|
|

Ok...here's a softball question...

I just need to be able to insert a key/value pair into an object at a specific position. I'm currently working with a Hashtable which, of course, doesn't allow for this functionality. What would be the best approach?

UPDATE: Also, I do need the ability to lookup by the key.

For example...oversimplified and pseudocoded but should convey the point

// existing Hashtable
myHashtable.Add("somekey1", "somevalue1");
myHashtable.Add("somekey2", "somevalue2");
myHashtable.Add("somekey3", "somevalue3");

// Some other object that will allow me to insert a new key/value pair.
// Assume that this object has been populated with the above key/value pairs.
oSomeObject.Insert("newfirstkey","newfirstvalue");

Thanks in advance.

© Stack Overflow or respective owner

Related posts about c#

Related posts about lists