Hello all,
I'm really struggling to find a way or method to convert my TimeSpan data type into an Int so I can put the value into an Array. Now I know you can't actually convert the TimeSpan variable into Int, but is there some sort of work around?
This is what I have so far:
DateTime startTime = DateTime.Now;
op1r:
Console.WriteLine("What is the Answer?");
Console.WriteLine();
Console.WriteLine("1 - Add");
Console.WriteLine("2 - Subtract");
Console.WriteLine("3 - Multiply");
Console.WriteLine("4 - Divide");
input = Console.ReadLine();
intInput = int.Parse(input);
if (intInput == 1)
{
DateTime stopTime = DateTime.Now;
TimeSpan duration = stopTime - startTime;
Console.WriteLine("Correct! Well Done!");
Console.WriteLine();
Console.WriteLine("Your Result:");
Console.WriteLine("Incorrect answers given: " + (incorrect));
Console.WriteLine("Time Taken: " + duration.Milliseconds + " Milliseconds");
Console.ReadLine();
duration = array;
goto start;
As you can see I have two DateTime.Now functions representing the start and finish, then the TimeSpan function which subtracts the two together to give me a time which is saved in variable duration. Then i've printed the time out to the application in the form of milliseconds.
Also, my array has 10 locations to store these times in. I want to be able to store each time in a particular location according to the value. For example, if I have a value of 5000 milliseconds, I want it to be stored in array location 5.
Any help on this matter would be greatly appreciated!
Kind regards,
NOLK.