tagged [foreach]
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`?
How does the Java 'for each' loop work?
How does the Java 'for each' loop work? Consider: What would the equivalent `for` loop look like without using the syntax?
- Modified
- 23 Feb at 13:21
Is the order of objects returned by FOREACH stable?
Is the order of objects returned by FOREACH stable? Is it safe to assume that two itterations over the same collection will return the objects in the same order? Obviously, it is assumed that the coll...
- Modified
- 26 Feb at 17:13
C# Break out of foreach loop after X number of items
C# Break out of foreach loop after X number of items In my foreach loop I would like to stop after 50 items, how would you break out of this foreach loop when I reach the 50th item? Thanks
Parallel.Foreach exceptions and cancel
Parallel.Foreach exceptions and cancel I have tried to find out how exceptions and cancel work for `Parallel.Foreach`. All examples seems to deal with Tasks. What happens on an exception in `Parallel....
- Modified
- 2 Mar at 10:41
C#: Any benefit of List<T>.ForEach(...) over plain foreach loop?
C#: Any benefit of List.ForEach(...) over plain foreach loop? I'm wondering why `List.ForEach(Action)` exists. Is there any benefit/difference in doing : over ?
ForEach to Trim string values in string array
ForEach to Trim string values in string array I just wondered why this ForEach doesn't work and leaves the values with trailing whitespace.
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...
- Modified
- 28 Oct at 09:21
Should I always use Parallel.Foreach because more threads MUST speed up everything?
Should I always use Parallel.Foreach because more threads MUST speed up everything? Does it make sense to you to use for every normal foreach a parallel.foreach loop ? When should I start using parall...
- Modified
- 6 Jan at 14:5
c# string.replace in foreach loop
c# string.replace in foreach loop Somehow I can't seem to get string replacement within a foreach loop in C# to work. My code is as follows : Am still quite new to LINQ so pardon me if this sounds ama...
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 ?
- Modified
- 26 Nov at 12:58
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...
What is the difference between for and foreach?
What is the difference between for and foreach? What is the major difference between `for` and `foreach` loops? In which scenarios can we use `for` and not `foreach` and vice versa. Would it be possib...
foreach loop with a where clause
foreach loop with a where clause I was wondering if it's possible to create a foreach loop in `C#` with a where loop. Not with a if statement inside, but and where clause in the declaring of the loop....
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...
- Modified
- 3 Dec at 15:18
ForEach() : Why can't use break/continue inside
ForEach() : Why can't use break/continue inside Since ForEach() method loop through all list members, Why can't I use a clause while I can use them inside a normal foreach loop Error: > "No enclosing ...
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...
- Modified
- 20 Jan at 23:8
What does the colon (:) operator do?
What does the colon (:) operator do? Apparently a colon is used in multiple ways in Java. Would anyone mind explaining what it does? For instance here: ``` String cardString = ""; for (PlayingCard c :...
How do I jump out of a foreach loop in C#?
How do I jump out of a foreach loop in C#? How do I break out of a `foreach` loop in C# if one of the elements meets the requirement? For example:
foreach day in month
foreach day in month > [How do I loop through a date range?](https://stackoverflow.com/questions/1847580/how-do-i-loop-through-a-date-range) Is there a way to make a foreach loop for each day in a s...
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
How does foreach work when looping through function results?
How does foreach work when looping through function results? Suppose I have the following code: Will `someObj.GetMyStrings()` be called on every iteration of the loop? Would it be better to do the fol...
Is there an equivalent to 'continue' in a Parallel.ForEach?
Is there an equivalent to 'continue' in a Parallel.ForEach? I am porting some code to `Parallel.ForEach` and got an error with a `continue` I have in the code. Is there something equivalent I can use ...
- Modified
- 20 Mar at 18:10
Does Class need to implement IEnumerable to use Foreach
Does Class need to implement IEnumerable to use Foreach This is in C#, I have a class that I am using from some else's DLL. It does not implement IEnumerable but has 2 methods that pass back a IEnumer...
- Modified
- 24 Sep at 13:52