Why is Parallel.ForEach much faster then AsParallel().ForAll() even though MSDN suggests otherwise?

This problem is pretty debuggable, an uncommon luxury when you have problems with threads. Your basic tool here is the Debug > Windows > Threads debugger window. Shows you the active threads and gives you a peek at their stack trace. You’ll easily see that, once it gets slow, that you’ll have dozens of threads … Read more

How does the enhanced for statement work for arrays, and how to get an iterator for an array?

If you want an Iterator over an array, you could use one of the direct implementations out there instead of wrapping the array in a List. For example: Apache Commons Collections ArrayIterator Or, this one, if you’d like to use generics: com.Ostermiller.util.ArrayIterator Note that if you want to have an Iterator over primitive types, you … Read more

How to modify an array’s values by a foreach loop?

Two ways, you can alter the memory location shared by the current value directly, or access the value using the source array. // Memory reference foreach ($bizaddarray as &$value) { $value = strip_tags(ucwords(strtolower($value))); } unset($value); # remove the reference Or // Use source array foreach ($bizaddarray as $key => $value) { $bizaddarray[$key] = strip_tags(ucwords(strtolower($value))); }

Why can’t we assign a foreach iteration variable, whereas we can completely modify it with an accessor?

foreach is a read only iterator that iterates dynamically classes that implement IEnumerable, each cycle in foreach will call the IEnumerable to get the next item, the item you have is a read only reference, you can not re-assign it, but simply calling item.Value is accessing it and assigning some value to a read/write attribute … Read more