• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 389
  • Last Modified:

insert a keyvaluePair in middle of dictionnary ?

Hello EE,
I have a dictionnary of integer, string

lets say :

1 , Earth
2, Hi
3, Hello Mona Lisa
4, Moon

lets say I do :

for each kvp as KeyValuePair(Of Integer, String) in dict
  if kvp.Value.Contains("Hello") then
         ---> here is my problem:   insert new KVP AFTER index 3 and put : 4, Hello Peter
  end if

so then 4,Moon would now be 5,Moon and so forth

is that possible ??
2 Solutions
Not without renumbering everything after the value you are trying to insert (i.e. removing and reinserting with a new key). But..... if this is really what you need then that more than likely means you have a poor implementation choice because your key once assigned should not change.

What is the purpose of what you are trying to do?
käµfm³d 👽Commented:
Agreed. Why not use a List(Of String) and use the implicit numbering you get with the index of the particular item (offsetting for zero, of course!)?
PhilippeRenaudAuthor Commented:
you're right. I should not use Dictionnary for my purpose.
list might be easier.

i was thinking that right afgter I press "submit your question" .. :P
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now