tagged [foreach]
Going Through A Foreach When It Can Get Modified?
Going Through A Foreach When It Can Get Modified? I want to do a foreach loop while taking out members of that foreach loop, but that's throwing errors. My only idea is to create another list inside o...
Changing Foreach Order?
Changing Foreach Order? Is there anyway to foreach through a list from the end to the beginning rather than the beginning to then end (preferably without reordering the list).
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...
Multiple Threads reading from the same file
Multiple Threads reading from the same file I have a xml file that needs to be read from many many times. I am trying to use the Parallel.ForEach to speed this processes up since none of that data bei...
- Modified
- 20 Aug at 00:28
Problems removing elements from a list when iterating through the list
Problems removing elements from a list when iterating through the list I have a loop that iterates through elements in a list. I am required to remove elements from this list within the loop based on ...
Why are assignment operators (=) invalid in a foreach loop?
Why are assignment operators (=) invalid in a foreach loop? Why are assignment operators (=) invalid in a `foreach` loop? I'm using C#, but I would assume that the argument is the same for other langu...
- Modified
- 23 Aug at 16:55
Is IEnumerable required to use a foreach loop?
Is IEnumerable required to use a foreach loop? I was wondering, when exactly can I use the foreach loop? Do I have to implement IEnumerable?
- Modified
- 27 Aug at 13:19
C# 4.0 'dynamic' and foreach statement
C# 4.0 'dynamic' and foreach statement Not long time before I've discovered, that new `dynamic` keyword doesn't work well with the C#'s `foreach` statement: ``` using System; sealed class Foo { publ...
- Modified
- 28 Aug at 01:39
Overload indexer to have foreach'able class
Overload indexer to have foreach'able class I tried to do something like this but this doesn't work: ``` class Garage { private List cars = new List(); public Car this[int i] { get...
Idiomatic way to use for-each loop given an iterator?
Idiomatic way to use for-each loop given an iterator? When the enhanced for loop (foreach loop) was added to Java, it was made to work with a target of either an array or `Iterable`. That works great ...
Bash foreach loop
Bash foreach loop I have an input (let's say a file). On each line there is a file name. How can I read this file and display the content for each one.
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...
How to check if a variable is an IEnumerable of some sort
How to check if a variable is an IEnumerable of some sort basically I'm building a very generic T4 template and one of the things I need it to do is say print `variable.ToString()`. However, I want it...
- Modified
- 4 Jan at 03:19
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://...
- Modified
- 13 Feb at 04:23
Is it possible to limit the cores for Parallel.ForEach?
Is it possible to limit the cores for Parallel.ForEach? I'm using a `Parallel.ForEach` in my code. All my 8 cores go to 100%. This is bad for the other apps that are running on the server.
- Modified
- 1 Apr at 10:57
foreach-ing through a listview and accessing subitems?
foreach-ing through a listview and accessing subitems? I'm having difficulty using a foreach statement with a WinForm ListView control. The following two code blocks demonstrates what I'm trying to do...
In .NET, using "foreach" to iterate an instance of IEnumerable<ValueType> will create a copy? So should I prefer to use "for" instead of "foreach"?
In .NET, using "foreach" to iterate an instance of IEnumerable will create a copy? So should I prefer to use "for" instead of "foreach"? In .NET, using "foreach" to iterate an instance of IEnumerable ...
- Modified
- 14 Apr at 13:34
Looping through Regex Matches
Looping through Regex Matches This is my source string: This is my Regex Patern: This is my Item class This is my Item Collection; I want to populate that list with Item's based on source strin
Modify Struct variable in a Dictionary
Modify Struct variable in a Dictionary I have a struct like this: But when I loop over it with foreach to change animation frame I can't do it... Here's the code: ``` foreach (KeyValuePair tile in til...
- Modified
- 6 Jun at 16:47
Modifying list inside foreach loop
Modifying list inside foreach loop I have a construction similar to this (but a more complicated): Now, I understand that its not possible to edit the c
Why C# compiler treated string class separately with foreach statement
Why C# compiler treated string class separately with foreach statement I clearly understand ["Pattern-based" approach](http://blogs.msdn.com/b/ericlippert/archive/2011/06/30/following-the-pattern.aspx...
C# - Using foreach to loop through method arguments
C# - Using foreach to loop through method arguments Is it possible to loop through a function arguments to check if any of them is null(or check them by another custom function)? something like this: ...
Less-verbose way of handling the first pass through a foreach?
Less-verbose way of handling the first pass through a foreach? I often find myself doing the following in a foreach loop to find out if I am on the or not. Is there a way to do this in , something alo...
Foreach loop, determine which is the last iteration of the loop
Foreach loop, determine which is the last iteration of the loop I have a `foreach` loop and need to execute some logic when the last item is chosen from the `List`, e.g.: Can I know which loop is last...
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...