Click here to Skip to main content
16,016,263 members
Home / Discussions / C#
   

C#

 
Questionforeach Dictionary Pin
George_George27-May-08 3:56
George_George27-May-08 3:56 
AnswerRe: foreach Dictionary Pin
buchstaben27-May-08 4:01
buchstaben27-May-08 4:01 
GeneralRe: foreach Dictionary Pin
George_George27-May-08 23:45
George_George27-May-08 23:45 
AnswerRe: foreach Dictionary Pin
Guffa27-May-08 4:24
Guffa27-May-08 4:24 
GeneralRe: foreach Dictionary Pin
George_George27-May-08 23:44
George_George27-May-08 23:44 
AnswerRe: foreach Dictionary Pin
J4amieC27-May-08 4:30
J4amieC27-May-08 4:30 
GeneralRe: foreach Dictionary Pin
George_George27-May-08 23:43
George_George27-May-08 23:43 
AnswerRe: foreach Dictionary Pin
The Nightcoder27-May-08 11:24
The Nightcoder27-May-08 11:24 
Yes, you're absolutely correct.

The only thing I'd like to add to your list of things we cannot do is: changing the order of the elements (by changing the key or whatever the elements are sorted on).

Everything else is fine.

Notes:

1. It is possible for someone to create an enumerable class (such as a dictionary) that supports all these operations from within a foreach loop. It all depends on how the enumerator and the rest of the class is implemented.

2. For performance reasons, enumerable classes are generally not thread-safe (unless the docs say they are). This means you have to think about not only what you do in the foreach loop, but also what other threads may be doing.

3. Testing this in the IDE (as someone suggested) may not help you much. It may work sometimes, and sometimes not, depending on how the dictionary is implemented, what it contains and exactly what you do. So the results may fool you.

Peter the small turnip

(1) It Has To Work. --RFC 1925[^]

GeneralRe: foreach Dictionary Pin
George_George27-May-08 23:41
George_George27-May-08 23:41 
GeneralRe: foreach Dictionary Pin
Guffa28-May-08 2:11
Guffa28-May-08 2:11 
GeneralRe: foreach Dictionary Pin
George_George28-May-08 15:35
George_George28-May-08 15:35 
GeneralRe: foreach Dictionary Pin
Guffa28-May-08 22:32
Guffa28-May-08 22:32 
GeneralRe: foreach Dictionary Pin
George_George31-May-08 2:37
George_George31-May-08 2:37 
GeneralRe: foreach Dictionary Pin
The Nightcoder28-May-08 2:44
The Nightcoder28-May-08 2:44 
GeneralRe: foreach Dictionary Pin
George_George28-May-08 15:49
George_George28-May-08 15:49 
GeneralRe: foreach Dictionary Pin
The Nightcoder28-May-08 21:48
The Nightcoder28-May-08 21:48 
GeneralRe: foreach Dictionary Pin
George_George31-May-08 2:36
George_George31-May-08 2:36 
GeneralRe: foreach Dictionary Pin
The Nightcoder2-Jun-08 2:20
The Nightcoder2-Jun-08 2:20 
GeneralRe: foreach Dictionary Pin
George_George3-Jun-08 2:36
George_George3-Jun-08 2:36 
GeneralRe: foreach Dictionary Pin
supercat96-Nov-08 9:12
supercat96-Nov-08 9:12 
GeneralRe: foreach Dictionary Pin
The Nightcoder28-May-08 22:01
The Nightcoder28-May-08 22:01 
Questionatomic operation of reference assignment? Pin
George_George27-May-08 3:40
George_George27-May-08 3:40 
AnswerRe: atomic operation of reference assignment? Pin
Guffa27-May-08 4:30
Guffa27-May-08 4:30 
GeneralRe: atomic operation of reference assignment? Pin
George_George27-May-08 23:54
George_George27-May-08 23:54 
GeneralRe: atomic operation of reference assignment? Pin
supercat910-Jul-08 7:07
supercat910-Jul-08 7:07 

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.