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 Query

More Query from same tag