Accepted answer

Yup, you just need some curly braces (and whitespace for good measure):

varEnumerable.ToList().ForEach(x => {

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 :)


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,...)

Related Articles