Solved

insert a keyvaluePair in middle of dictionnary ?

Posted on 2013-01-23
3
375 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 74

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now