tagged [foreach]

Are Parallel.Invoke and Parallel.ForEach essentially the same thing?

Are Parallel.Invoke and Parallel.ForEach essentially the same thing? And by "same thing" I mean do these two operations basically do the same work, and it just boils down to which one is more convenie...

How to implement for-else and foreach-else in C# similar to Python's for-else and while-else?

How to implement for-else and foreach-else in C# similar to Python's for-else and while-else? Python's and loops include an optional clause which execute if the loop exits normally ( without a stateme...

7 Nov at 17:30

Lambda Expression using Foreach Clause

Lambda Expression using Foreach Clause > [Why is there not a ForEach extension method on the IEnumerable interface?](https://stackoverflow.com/questions/101265/why-is-there-not-a-foreach-extension-met...

26 Oct at 05:58

Parallel.ForEach loop with BlockingCollection.GetConsumableEnumerable

Parallel.ForEach loop with BlockingCollection.GetConsumableEnumerable Why `Parallel.ForEach` loop exits with `OperationCancelledException`, while using `GetConsumableEnumerable`? ``` //outside the fun...

how do I check if an entity is the first element of a foreach loop

how do I check if an entity is the first element of a foreach loop Say I have a `foreach` loop. I have to do something with the first object of the loop that I don't have to do with any of the other o...

25 Mar at 05:20

Performance difference for control structures 'for' and 'foreach' in C#

Performance difference for control structures 'for' and 'foreach' in C# Which code snippet will give better performance? The below code segments were written in C#. 1. ``` for(int tempCount=0;tempCoun...

20 Jan at 23:8

Changing objects value in foreach loop?

Changing objects value in foreach loop? In one place i am using the list of string in that case the i am able to change the value of the string as code given below, But for object of class i am not ab...

30 Dec at 12:54

JSON forEach get Key and Value

JSON forEach get Key and Value I have the following `forEach` loop over a JSON object called `obj`: How can I make it `console.log` both `key` and `value` of each item inside the object? Something lik...

3 Dec at 15:18

change values in array when doing foreach

change values in array when doing foreach example: The array is still with it's original values, is there any way to have writing access to array's elements from iterating function ?

Short circuit Array.forEach like calling break

Short circuit Array.forEach like calling break How can I do this using the new `forEach` method in JavaScript? I've tried `return;`, `return false;` and `break`. `break` crashes and `return` does noth...

28 Oct at 09:21

How to 'foreach' a column in a DataTable using C#?

How to 'foreach' a column in a DataTable using C#? How do I loop through each column in a datarow using `foreach`?

11 Sep at 19:0

Loop through all the rows of a temp table and call a stored procedure for each row

Loop through all the rows of a temp table and call a stored procedure for each row I have declared a temp table to hold all the required values as follows: ``` DECLARE @temp TABLE ( Password INT, ...

break out of if and foreach

break out of if and foreach I have a foreach loop and an if statement. If a match is found i need to ultimately break out of the foreach.

13 Jul at 14:34

Iterate over elements of List and Map using JSTL <c:forEach> tag

Iterate over elements of List and Map using JSTL tag If I have a JSF backing bean return an object of type ArrayList, I should be able to use `` to iterate over the elements in the list. Each element ...

20 Jun at 09:12

"Avoid allocations in compiler hot paths" Roslyn Coding Conventions

"Avoid allocations in compiler hot paths" Roslyn Coding Conventions I've been reading through the [Contributing Code](https://roslyn.codeplex.com/wikipage?title=How%20to%20Contribute&referringTitle=Ho...

20 Jun at 09:12

Is there a foreach construct in TypeScript similar to the C# implementation?

Is there a foreach construct in TypeScript similar to the C# implementation? I really like using the `foreach` construct for "for loops" in C#. I think it's very clean, efficient and readable. Is the...

How do I exit a foreach loop in C#?

How do I exit a foreach loop in C#? Whenever violated is true, I want to get o

13 Mar at 14:45

How to get values of selected items in CheckBoxList with foreach in ASP.NET C#?

How to get values of selected items in CheckBoxList with foreach in ASP.NET C#? I have a CheckBoxList like this: ``` TG Gold Silver NE

19 Feb at 21:9

Linq style "For Each"

Linq style "For Each" Is there any Linq style syntax for "For each" operations? For instance, add values based on one collection to another, already existing one: Instead of

31 Jan at 07:11

Declare variable in Razor

Declare variable in Razor I want to add a variable outside the foreach and then use that inside the foreach loop ``` Date Location @int i; @foreach (var item in Model) { i=0; ...

Getting "The connection does not support MultipleActiveResultSets" in a ForEach with async-await

Getting "The connection does not support MultipleActiveResultSets" in a ForEach with async-await I have the following code using Dapper.SimpleCRUD : ``` var test = new FallEnvironmentalCondition[] { ...

Difference between "as $key => $value" and "as $value" in PHP foreach

Difference between "as $key => $value" and "as $value" in PHP foreach I have a database call and I'm trying to figure out what the `$key => $value` does in a `foreach` loop. The reason I ask is becaus...

14 Nov at 11:19

Does foreach() iterate by reference?

Does foreach() iterate by reference? Consider this: Is `obj` a reference to the corresponding object within the list so that when I change the property the change will persist in the object instance o...

30 Sep at 09:0

Go to "next" iteration in JavaScript forEach loop

Go to "next" iteration in JavaScript forEach loop How do I go to the next iteration of a JavaScript `Array.forEach()` loop? For example: [MDN docs](https://developer.mozilla.org/en-US/docs/Web/JavaScr...

11 Aug at 22:45

PHP PDO with foreach and fetch

PHP PDO with foreach and fetch The following code: ``` "; $sql = "SELECT * FROM users"; $users = $dbh->query($sql); foreach ($users as $row) { print $row["name"] . "-" . $row["sex"] .""; }...

8 Jul at 00:2