score:11
yup, you just need some curly braces (and whitespace for good measure):
varenumerable.tolist().foreach(x => {
mymethod(x);
thread.sleep(2000);
});
edit: it's been noted in the comments on the question that this is less efficient than a plain foreach (due to the tolist()
call), and by the time you add the braces and whitespace it doesn't look any cleaner, so it's not really a big win. so this is how you can do what you asked for, but it's probably not what you should do :)
score:4
what about:
varenumerable.tolist().foreach(x => {mymethod(x);thread.sleep(2000);});
you can group multiple commands using accolades ({}
) and semicolons (;
).
note that you can use any kind of instructions in such environment (for
loops, instructions,...)
Source: stackoverflow.com
Related Query
- Is it possible to have Thread.Sleep() in a single List<T> ForEach?
- Is it possible to have one LINQ in one line of code for
- c# Linq or code to extract groups from a single list of source data
- Can LINQ ForEach have if statement?
- Is it possible to express this code in LINQ?
- Is it possible to have an out ParameterExpression?
- is it possible to have a conditional field in an anonymous type
- Why is my code doing lazy loading even after I turned it off at every possible point?
- .NET String parsing performance improvement - Possible Code Smell
- LINQ Source Code Available
- .NET 4 Code Contracts: "requires unproven: source != null"
- Removing a single item from an enumerable source when the items are equal
- Updating single Column of List without Foreach Loop
- Consolidate many if conditions to a single LINQ statement if possible
- Is it possible to convert foreach operation into LINQ if it does two things?
- Is it possible to get Entity Framework to recognize objects that have been created and not yet saved in database?
- C# Linq query help removing foreach loops creating cleaner code
- Is it possible to have fall-back for empty values in a LINQ query considering locale?
- convert foreach loop to linq code
- Is it possible to replace this foreach loop with Linq?
- Is it possible to have an anonymous method when creating a list of items, with .NET + Linq?
- Is LINQifying my code worth accessing a foreach variable in a closure?
- creating Linq to sqlite dbml from DbLinq source code
- Binding source thread in PLINQ
- Need a LINQ code example to link two tables that have no foreign key
- How to debug this or possible causes? System.NullReferenceException was unhandled by user code on Moq.Verify
- How to flatten a multi level XML into a single level XML using c# code LINQ
- Is it possible to do this as a single efficient LINQ query?
- Entity Framework Code First - Get blog posts which have certain tags
- Is it possible to rewrite the below code in Linq/Lambda approach
More Query from same tag
- Select all available fields in LINQ query when joining two DataTables
- LINQ - Removing items in a List<T> that contain one item of an Array in any order or position
- Violation of PRIMARY KEY constraint on insert
- Dynamic Columns in LINQ
- Converting an SQL with Left Join , Group and Sum to a Linq Query
- Generating a kml file on the fly using C# and Linq
- LINQ to entities against EF in many to many relationship
- How to get the value of a field from Lambda expression for ForEach()?
- GroupBy using a list of strings
- Passing an IComparer parameter to custom LINQ OrderBy extension method
- Get Average Using LINQ
- How to convert SQL to linq for this query
- Get indexes of all matching values from list using Linq
- Full outer join with linq for 3 tables
- Exception: The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type
- C# : using lambda to GroupBy every collection elements
- LINQ analogues in Scala?
- how to write LINQ to objects equivalent code for this code
- LINQ - Compare List objects and List of strings
- Linq to Sql Inner Join
- How do I dynamically create an Expression<Func<MyClass, bool>> predicate from Expression<Func<MyClass, string>>?
- Returning Index in Enumerable Select
- Insert chunk using linq to sql?
- Get all <td> title of a table column with coded ui
- LINQ Query with multiple conditions and setting values into a list
- How do I convert SQL Query with Ccase Switch to Linq Lambda
- Why does Select(x => ...Cast<x.GetType()>()) not work?
- LINQ query finding object with closest data variable to query input variable
- Where to call .AsParallel() in a LINQ query
- How to get max sum range for specific time period from values in Dictionary