Click here to Skip to main content
15,888,733 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralMessage Removed Pin
29-Apr-10 6:07
professionalN_tro_P29-Apr-10 6:07 
GeneralRe: lock Pin
Covean29-Apr-10 6:23
Covean29-Apr-10 6:23 
GeneralRe: lock Pin
Alex Manolescu29-Apr-10 11:34
Alex Manolescu29-Apr-10 11:34 
GeneralRe: lock Pin
Dave Kreskowiak29-Apr-10 7:01
mveDave Kreskowiak29-Apr-10 7:01 
GeneralRe: lock Pin
Covean29-Apr-10 6:13
Covean29-Apr-10 6:13 
GeneralRe: lock Pin
supercat929-Apr-10 9:11
supercat929-Apr-10 9:11 
GeneralRe: lock Pin
Luc Pattyn29-Apr-10 9:38
sitebuilderLuc Pattyn29-Apr-10 9:38 
GeneralRe: lock Pin
supercat929-Apr-10 13:10
supercat929-Apr-10 13:10 
Luc Pattyn wrote:
For collections there should at least be an enumerator that allows modifications to the elements that have already been visited including removal from the collection, so one could e.g. easily remove elements that satisfy some conditions while enumerating them all.


I would think there should be. Unfortunately, Microsoft's contract for iEnumerable/iEnumerator explicitly forbids them from even allowing such a thing; it requires that an attempt to fetch the next item from an iEnumerator throw an exception if any change has been made to the underlying iEnumerable even if the iEnumerator would otherwise be able to return something useful. Note that the vb6-style "Collection" object does not conform to this but instead returns useful data (hooray!) Too bad no other collections behave similarly.

If I had my druthers, an iEnumerator would be only be required to throw an exception if it couldn't otherwise meet the following contract:

  1. Any item that exists throughout the enumeration will be returned exactly once in each pass through the enumeration.
  2. Any item that is added and/or removed during the enumeration will be returned zero or one times (a removal and re-add may create a "new" item) in any pass.
  3. For collections with keys, changing a key may be regarded as a remove and add, which may be performed in either order.
  4. Items will be returned in a sequence consistent with the contract (e.g. if a particular collection is supposed to return items in sorted order, adding and deleting items should not cause items to be returned out of sequence).
  5. If the effect of an addition or removal is observed in one pass through the enumeration, it will be observed in subsequent passes.

For some types of collection, it would be difficult to meet this contract. Such collections should throw exceptions if they're modified during enumeration. On the other hand, if a collection can meet the above conditions even if it's changed during enumeration, why shouldn't it be allowed to?
GeneralRe: lock Pin
Luc Pattyn29-Apr-10 13:56
sitebuilderLuc Pattyn29-Apr-10 13:56 
GeneralRe: lock Pin
supercat930-Apr-10 5:02
supercat930-Apr-10 5:02 
GeneralRe: lock Pin
Luc Pattyn30-Apr-10 5:19
sitebuilderLuc Pattyn30-Apr-10 5:19 
GeneralEnumerators Pin
supercat930-Apr-10 6:12
supercat930-Apr-10 6:12 
GeneralRe: Enumerators Pin
Luc Pattyn30-Apr-10 9:18
sitebuilderLuc Pattyn30-Apr-10 9:18 
GeneralRe: Enumerators Pin
supercat930-Apr-10 11:31
supercat930-Apr-10 11:31 
QuestionReference a .NET 3.5 assembly form a .NET 2.0 other assembly: in VS2008 ok, not in VS2010 Pin
Ferdinando Santacroce29-Apr-10 3:22
Ferdinando Santacroce29-Apr-10 3:22 
AnswerRe: Reference a .NET 3.5 assembly form a .NET 2.0 other assembly: in VS2008 ok, not in VS2010 Pin
Not Active29-Apr-10 3:35
mentorNot Active29-Apr-10 3:35 
GeneralRe: Reference a .NET 3.5 assembly form a .NET 2.0 other assembly: in VS2008 ok, not in VS2010 Pin
Luc Pattyn29-Apr-10 4:18
sitebuilderLuc Pattyn29-Apr-10 4:18 
AnswerRe: Reference a .NET 3.5 assembly form a .NET 2.0 other assembly: in VS2008 ok, not in VS2010 Pin
Ferdinando Santacroce29-Apr-10 5:54
Ferdinando Santacroce29-Apr-10 5:54 
QuestionAny Problem with VS 2010 Ultimate? if VS 2008 already exists.. Pin
yadlaprasad29-Apr-10 1:26
yadlaprasad29-Apr-10 1:26 
AnswerRe: Any Problem with VS 2010 Ultimate? if VS 2008 already exists.. Pin
Michel Godfroid29-Apr-10 1:47
Michel Godfroid29-Apr-10 1:47 
AnswerRe: Any Problem with VS 2010 Ultimate? if VS 2008 already exists.. Pin
Not Active29-Apr-10 1:56
mentorNot Active29-Apr-10 1:56 
QuestionSetting DisplayMember & ValueMember with DataTable Pin
massaslayer28-Apr-10 10:21
massaslayer28-Apr-10 10:21 
AnswerRe: Setting DisplayMember & ValueMember with DataTable Pin
Ashfield29-Apr-10 3:39
Ashfield29-Apr-10 3:39 
Questionlinking two tables Pin
kolisa28-Apr-10 1:29
kolisa28-Apr-10 1:29 
AnswerRe: linking two tables Pin
Dave Kreskowiak28-Apr-10 2:17
mveDave Kreskowiak28-Apr-10 2:17 

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.