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
Post a Comment