c# - Is it possible to have Thread.Sleep() in a single List<T> ForEach? -


is possible rewrite following code in single statement?

foreach(var myvar in varenumerable) {     mymethod(myvar);     thread.sleep(2000); } 

without thread.sleep(), would've written as:

varenumerable.tolist().foreach(x => mymethod(x)); 

yup, need curly braces (and whitespace measure):

varenumerable.tolist().foreach(x => {     mymethod(x);     thread.sleep(2000); }); 

edit: it's been noted in comments on question less efficient plain foreach (due tolist() call), , time add braces , whitespace doesn't cleaner, it's not big win. how can asked for, it's not should :)


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -