Stories recently tagged with 'foreach'

C# Working With ArrayList: What is the best Iterator choice?(coderpaws.blogspot.com)

submitted by CoderPawsCoderPaws(140) 1 year, 8 months ago

When you first look at which statement to use to iterate through an ArrayList collection, the foreach statement stands out. It's syntax is concise and readable as well as no extra lines of code are needed to extract the element you want to work with. But...[pause for effect]...if the collection is changed (e.g. adding, modifying, or deleting elements and even copying to it), you'll get a runtime error that the "Collection was modified." read more...

1 comment |category: |Views: 346

tags: another

Lists: Filter, Map and Reduce - and the Magic of IEnumerator.(honestillusion.com)

submitted by JamesCurran2JamesCurran2(134) 3 years, 9 months ago

There are 3 very handy list functions which make dealing with lists a breeze: Map, Filter and Reduce. But along the way of writing them, an important principle of IEnumerator<> comes up. read more...

add a comment |category: |Views: 63

tags: another

Why System.Linq.Enumerable doesn't have a ForEach extension method(gregbeech.com)

submitted by gregbeechgregbeech(76) 3 years, 10 months ago

Lots of people suggest a ForEach method would be a good addition to the base class framework. This is why I don't think it would be, even though our core library has an implementation of it. read more...

add a comment |category: |Views: 176

tags: another

JavaScript ForEach Equivalent(pietschsoft.com)

submitted by crpietschmanncrpietschmann(11.3k) 4 years, 2 months ago

One thing with the For Loop in JavaScript is it doesn't seem to be very well documented that you can use it to do an equivalent of a ForEach loop. Here's a short example of doing the ForEach loop equivalent in JavaScript using the "in" keyword. read more...

add a comment |category: |Views: 215

tags: another

Create elegant code with Action delegate and List.ForEach method(dotnettipoftheday.org)

submitted by manovichmanovich(755) 4 years, 6 months ago

Small example of how to use Action delegate to perform some action on all elements of a collection. read more...

9 comments |category: |Views: 645

tags: another

What's inside a foreach() statement?(honestillusion.com)

submitted by JamesCurran2JamesCurran2(134) 5 years ago

A comparision of a foreach() loop and manually looping by calling GetEnumerator() and MoveNext() read more...

add a comment |category: |Views: 3

tags: another

Only iterating over the objects you want in a foreach loop(jeremyjarrell.com)

submitted by jeremyjarrelljeremyjarrell(2685) 5 years, 3 months ago

Have you ever had a collection made of several types which all derive from the same base class? How many times have you needed to iterate the whole collection and check each element to make sure its the type that you want to work with? Here's how to do you type checking completely inline inside of the foreach loop so you only get the objects you want. read more...

1 comment |category: |Views: 8

tags: another

Performance of foreach vs. List.ForEach(diditwith.net)

submitted by cls2degcls2deg(1535) 5 years, 7 months ago

Today I was iterating a List<int> using a foreach-loop and feeling a bit smug in knowing how much more performance-conscious I was being than if I'd tried doing the same thing with an ArrayList filled with ints. Thanks to the wonder of generics, the C# compiler neatly avoids numerous boxing operations by using a System.Collections.Generic.IEnumerator<int> instance instead of the older System.Collections.IEnumerator. Then I got to thinking: "is this really the fastest way?" Upon investigation, it turns that, no, it isn't the fastest way. read more...

1 comment |category: |Views: 367

tags: another