tagged [foreach]

Check if object value exists within a Javascript array of objects and if not add a new object to array

Check if object value exists within a Javascript array of objects and if not add a new object to array If I have the following array of objects: Is there a way to loop through the array to check wheth...

Max Degree of Parallelism for AsParallel()

Max Degree of Parallelism for AsParallel() While using `Parallel.ForEach` we have the option to define the Parallel options and set the Max Degree of Parallelism like : But while doing PLINQ like: I w...

Trying to get property of non-object in

Trying to get property of non-object in on Control page: on View Page: Error

18 Sep at 15:20

For..In loops in JavaScript - key value pairs

For..In loops in JavaScript - key value pairs I was wondering if there's a way to do something like a PHP `foreach` loop in JavaScript. The functionality I'm looking for is something like this PHP Sni...

22 Feb at 13:29

Check for null in foreach loop

Check for null in foreach loop Is there a nicer way of doing the following: I need a check for null to happen on file.Headers before proceeding with the loop In short it looks a bit ugly to write the...

31 Jul at 06:31

Why can't I do foreach (var Item in DataTable.Rows)?

Why can't I do foreach (var Item in DataTable.Rows)? Is there a reason why I can't do the following: rather than having to do I would have thought this was possible, like it is on other datatypes. For...

18 Aug at 18:9

Counter in foreach loop in C#

Counter in foreach loop in C# As I know, > So, if I have n items in an array. then, In, 1st iteration, then, in 2nd, . . . in last (nth), from working it seems that at each iteration it knows that...

2 Dec at 17:2

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

Why can't we assign a foreach iteration variable, whereas we can completely modify it with an accessor? I was just curious about this: the following code will not compile, because we cannot modify a f...

20 Oct at 15:11

Break parallel.foreach?

Break parallel.foreach? [parallel.for](http://msdn.microsoft.com/en-us/library/system.threading.tasks.parallel.for.aspx) I have a pretty complex statement which looks like the following: ``` Parallel....

Why is the C# compiler happy with double IEnumerable<T> and foreach T?

Why is the C# compiler happy with double IEnumerable and foreach T? I know this code does not work (and have no problems writing it in a way that will work). I was wondering how the compiler can build...

25 Nov at 22:41

System.Timers.Timer massively inaccurate

System.Timers.Timer massively inaccurate I've written a program which uses all available cores by using `Parallel.ForEach`. The list for the `ForEach` contains ~1000 objects and the computation for ea...

Error in datarow,Collection was modified; enumeration operation might not execute

Error in datarow,Collection was modified; enumeration operation might not execute I have for-each loop in which the data row is updated so the exception , is generated. any way to fix it? i have seen ...

6 Jun at 06:40

How to skip a specific position within a for each loop in c sharp?

How to skip a specific position within a for each loop in c sharp? ``` List liste = new List { "A","B","C","D" }; foreach (var item in liste) { System.Diagnostics.Debug.Wri...

30 Oct at 00:2

Get out of multiple loops?

Get out of multiple loops? > [Breaking out of a nested loop](https://stackoverflow.com/questions/324831/breaking-out-of-a-nested-loop) I have this code But `break` only "breaks" the most inner

23 May at 12:24

Skip items of a specific type in foreach loop

Skip items of a specific type in foreach loop I have this code for filling datatable from excel file: I h

26 Jan at 10:59

Are there any side effects of returning from inside a foreach statement?

Are there any side effects of returning from inside a foreach statement? Similar to my question about [returning from inside a using statement](https://stackoverflow.com/questions/2369887/are-there-an...

23 May at 10:29

Restart a foreach loop in C#?

Restart a foreach loop in C#? How can I restart a `foreach` loop in C#?? For example: `restart` here is like `continue` or `break` but it restarts the foreach from the begining It is like setting the ...

22 Aug at 06:20

Does foreach automatically call Dispose?

Does foreach automatically call Dispose? In C#, Does foreach automatically call Dispose on any object implementing IDisposable? [http://msdn.microsoft.com/en-us/library/aa664754(v=vs.71).aspx](http://...

13 Feb at 04:23

C#, Looping through dataset and show each record from a dataset column

C#, Looping through dataset and show each record from a dataset column In C#, I'm trying to loop through my dataset to show data from each row from a specific column. I want the get each date under th...

6 Mar at 16:17

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; ...

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

Parallel.ForEach and async-await

Parallel.ForEach and async-await I had such method: Then I decided to use `Parallel.ForEach`: ``` pub

Why does List<T>.ForEach() implement a for loop?

Why does List.ForEach() implement a for loop? I don't understand why the `List.ForEach()` extension method implements a `for` loop under the hood. This opens up the possibility of the collection being...

3 May at 19:51

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

laravel foreach loop in controller

laravel foreach loop in controller i have a problem about looping data in controller (laravel 4). my code is like this: when i want to use foreach to loop for $product result with code like this: ``` ...

18 Jun at 05:8