- Start off by creating two methods in the Demo class. Call one method ReadCollectionForEach() and pass it a parameter of List<string>. Create a second method called ReadCollectionParallelForEach() that also accepts a parameter of List<string>:
public class Demo { public double ReadCollectionForEach(List<string> intCollection) { } public double ReadCollectionParallelForEach(List<string> intCollection) { } }
- In the ReadCollectionForEach() method, add a standard foreach loop that will iterate over the collection of strings passed to it and write the value it finds to the console window. Then, clear the console window. Use a timer to keep track of the total seconds elapsed during the foreach loop:
var timer = Stopwatch.StartNew(); ...