tagged [foreach]
What's the fastest way to copy the values and keys from one dictionary into another in C#?
What's the fastest way to copy the values and keys from one dictionary into another in C#? There doesn't seem to be a dictionary.AddRange() method. Does anyone know a better way to copy the items to a...
- Modified
- 18 Sep at 08:24
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
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.
- Modified
- 13 Jul at 14:34
Cannot assign void to an implicitly-typed local variable with var and foreach
Cannot assign void to an implicitly-typed local variable with var and foreach I'm trying to list all buttons name from my form to list with code and always get error > Cannot assign void to an implici...
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...
Is a LINQ statement faster than a 'foreach' loop?
Is a LINQ statement faster than a 'foreach' loop? I am writing a Mesh Rendering manager and thought it would be a good idea to group all of the meshes which use the same shader and then render these w...
- Modified
- 29 Aug at 15:29
Combining foreach and using
Combining foreach and using I'm iterating over a ManageObjectCollection.( which is part of WMI interface). However the important thing is, the following line of code. : The point is that ManageObject ...
- Modified
- 9 Jun at 11:32
Iterate Multi-Dimensional Array with Nested Foreach Statement
Iterate Multi-Dimensional Array with Nested Foreach Statement I think this might be a pretty simple question, but I haven't been able to figure it out yet. If I've got a 2-dimensional array like so: W...
- Modified
- 12 Sep at 12:1
Operator '??' cannot be applied to operands of type 'System.DateTime'
Operator '??' cannot be applied to operands of type 'System.DateTime' I get the following error : --- ``` foreach (EndServReward r in reward) { if (con.State == Connectio...
- Modified
- 27 Oct at 14:22
How do you get the index of the current iteration of a foreach loop?
How do you get the index of the current iteration of a foreach loop? Is there some rare language construct I haven't encountered (like the few I've learned recently, some on Stack Overflow) in C# to g...
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...
Is there a way to iterate over a dictionary?
Is there a way to iterate over a dictionary? I know `NSDictionaries` as something where you need a `key` in order to get a `value`. But how can I iterate over all `keys` and `values` in a `NSDictionar...
- Modified
- 11 Jun at 12:44
How can I access the next value in a collection inside a foreach loop in C#?
How can I access the next value in a collection inside a foreach loop in C#? I'm working in C# and with a sorted `List` of structs. I'm trying to iterate through the `List` and for each iteration I'd ...
Why can't I set properties of iteration variables in a foreach loop?
Why can't I set properties of iteration variables in a foreach loop? I expected the above line to return true. W
c# parallel foreach loop finding index
c# parallel foreach loop finding index I am trying to read all lines in a text file and planning to display each line info. How can I find the index for each item inside loop? ``` string[] lines = Fil...
- Modified
- 21 Feb at 16:33
Get current index from foreach loop
Get current index from foreach loop Using C# and Silverlight How do I get the index of the current item in the list? Code: ``` IEnumerable list = DataGridDetail.ItemsSource as IEnumerable; List lstFil...
- Modified
- 27 Apr at 08:9
How do I pass 2 lists into Parallel.ForEach?
How do I pass 2 lists into Parallel.ForEach? How do I pass 2 lists into `Parallel.ForEach`? Example: I would prefer to avoid encapsulating P
- Modified
- 15 Jan at 11:32
Does the foreach loop in C# guarantee an order of evaluation?
Does the foreach loop in C# guarantee an order of evaluation? Logically, one would think that the foreach loop in C# would evaluate in the same order as an incrementing for loop. Experimentally, it do...
Debugging a foreach loop in C#: what iteration is this?
Debugging a foreach loop in C#: what iteration is this? Other than setting a debug variable and incrementing it every time you start the foreach, when you break in with the Visual Studio debugger conn...
- Modified
- 28 Jul at 12:11
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...
How does the enhanced for statement work for arrays, and how to get an iterator for an array?
How does the enhanced for statement work for arrays, and how to get an iterator for an array? Given the following code snippet: I have the following questions: 1. How does the above for-each loop work...
How is foreach implemented in C#?
How is foreach implemented in C#? How exactly is `foreach` implemented in C#? I imagine a part of it looking like: However I'm unsure what's really going on. What methodology is used for returning `en...
- Modified
- 24 Jun at 16:36
Conditional C# breakpoint?
Conditional C# breakpoint? I'm debugging a `foreach` loop which will iterate well over 1000 times - so I only want a breakpoint within the loop to break for a particular item. So... Do I have to write...
- Modified
- 30 Apr at 16:12
What is the for/while equivalent of foreach?
What is the for/while equivalent of foreach? I have a `foreach` loop that needs converting to a `for` or `while` loop. My loop looks like this: What is the equivalent `for` or `while` loop? I think I ...
- Modified
- 21 Aug at 15:51