Click here to Skip to main content
15,887,214 members
Home / Discussions / C#
   

C#

 
GeneralRe: my Dictionary removal code correct? Pin
George_George17-May-08 21:15
George_George17-May-08 21:15 
GeneralRe: my Dictionary removal code correct? Pin
PIEBALDconsult18-May-08 5:02
mvePIEBALDconsult18-May-08 5:02 
GeneralRe: my Dictionary removal code correct? Pin
George_George19-May-08 1:02
George_George19-May-08 1:02 
GeneralRe: my Dictionary removal code correct? Pin
PIEBALDconsult19-May-08 12:58
mvePIEBALDconsult19-May-08 12:58 
GeneralRe: my Dictionary removal code correct? Pin
George_George20-May-08 4:02
George_George20-May-08 4:02 
GeneralRe: my Dictionary removal code correct? Pin
PIEBALDconsult20-May-08 14:17
mvePIEBALDconsult20-May-08 14:17 
GeneralRe: my Dictionary removal code correct? Pin
George_George21-May-08 0:35
George_George21-May-08 0:35 
AnswerRe: my Dictionary removal code correct? Pin
Guffa17-May-08 6:21
Guffa17-May-08 6:21 
If you remove an item from the dictionary, that will invalidate the enumerator that the foreach command is using, so it's not possible to remove items in a loop like that.

Do like this:
List<string> remove = new List<string>();
foreach (KeyValuePair<sting, foo=""> item in dic) if (item.Value.order > 100) remove.Add(item.Key);
foreach (string key in remove) dic.Remove(key);</sting,>


Despite everything, the person most likely to be fooling you next is yourself.

GeneralRe: my Dictionary removal code correct? Pin
George_George17-May-08 21:12
George_George17-May-08 21:12 
GeneralRe: my Dictionary removal code correct? Pin
Guffa18-May-08 1:40
Guffa18-May-08 1:40 
GeneralRe: my Dictionary removal code correct? Pin
George_George18-May-08 1:43
George_George18-May-08 1:43 
AnswerRe: my Dictionary removal code correct? Pin
Roger Alsing17-May-08 7:22
Roger Alsing17-May-08 7:22 
GeneralRe: my Dictionary removal code correct? Pin
George_George17-May-08 21:07
George_George17-May-08 21:07 
Questionoverriding Pin
angels77717-May-08 3:09
angels77717-May-08 3:09 
AnswerRe: overriding [modified] Pin
Anthony Mushrow17-May-08 7:12
professionalAnthony Mushrow17-May-08 7:12 
QuestionRunninng a clickonce deployed app from VBA Pin
rotsey17-May-08 3:08
rotsey17-May-08 3:08 
Questionwhy we need registry ? Pin
prasadbuddhika17-May-08 3:05
prasadbuddhika17-May-08 3:05 
AnswerRe: why we need registry ? Pin
PIEBALDconsult17-May-08 5:02
mvePIEBALDconsult17-May-08 5:02 
AnswerRe: why we need registry ? Pin
Hamid_RT17-May-08 7:35
Hamid_RT17-May-08 7:35 
Questionmemory footprint of Dictionary Pin
George_George17-May-08 1:50
George_George17-May-08 1:50 
AnswerRe: memory footprint of Dictionary Pin
Guffa17-May-08 3:26
Guffa17-May-08 3:26 
GeneralRe: memory footprint of Dictionary Pin
George_George17-May-08 3:35
George_George17-May-08 3:35 
GeneralRe: memory footprint of Dictionary Pin
Guffa17-May-08 6:29
Guffa17-May-08 6:29 
GeneralRe: memory footprint of Dictionary Pin
George_George17-May-08 21:31
George_George17-May-08 21:31 
GeneralRe: memory footprint of Dictionary Pin
Guffa18-May-08 12:34
Guffa18-May-08 12:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.