Solved

insert a keyvaluePair in middle of dictionnary ?

Posted on 2013-01-23
3
379 Views
Last Modified: 2013-01-23
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
next

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


is that possible ??
0
Comment
Question by:PhilippeRenaud
3 Comments
 
LVL 4

Assisted Solution

by:mcmahon_s
mcmahon_s earned 250 total points
ID: 38811883
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?
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 38811940
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!)?
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 38811976
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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question