c# - Why there is no ForEach extension method on IEnumerable? -


inspired question asking missing zip function:

why there no foreach extension method in enumerable class? or anywhere? class gets foreach method list<>. there reason why it's missing (performance)?

there foreach statement included in language job of time.

i'd hate see following:

list.foreach( item => {     item.dosomething(); } ); 

instead of:

foreach(item item in list) {      item.dosomething(); } 

the latter clearer , easier read in situation, although maybe bit longer type.

however, must admit changed stance on issue; foreach() extension method indeed useful in situations.

here major differences between statement , method:

  • type checking: foreach done @ runtime, foreach() @ compile time (big plus!)
  • the syntax call delegate indeed simpler: objects.foreach(dosomething);
  • foreach() chained: although evilness/usefulness of such feature open discussion.

those great points made many people here , can see why people missing function. wouldn't mind microsoft adding standard foreach method in next framework iteration.


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -