I'm creating an UWP application that needs to measure the time the user is looking at an object. This application has around 300 objects to measure the time of. To do this we will be using around 300 timers. To achieve this we will have to create 300 stopwatches individually which is highly inefficient.
The timer starts when the user is looking at the corresponding object and stops when the user is no longer looking at the corresponding object. If the user's gaze is fixated on the corresponding object again the timer of course starts again. At the end all of the times of the stopwatches will be saved into a file. Creating 300 stopwatches requires a new line of code for every stopwatch which does not seem very efficient. I have tried to automate the stopwatch creation process by using Enumerable.range but so far i have not been able to find a solution.
/// <summary>
/// All stopwatches for every word. In our real code we will have around 300 stopwatches.
/// </summary>
Stopwatch Stopwatch1 = new Stopwatch();
Stopwatch Stopwatch2 = new Stopwatch();
Stopwatch Stopwatch3 = new Stopwatch();
Stopwatch Stopwatch4 = new Stopwatch();
Stopwatch Stopwatch5 = new Stopwatch();
Stopwatch Stopwatch6 = new Stopwatch();
Stopwatch Stopwatch7 = new Stopwatch();
Stopwatch Stopwatch8 = new Stopwatch();
Stopwatch Stopwatch9 = new Stopwatch();
Stopwatch Stopwatch10 = new Stopwatch();
See Question&Answers more detail:os