I want to write a simple stopwatch program, I can make it work with the following code
public Form1()
{
InitializeComponent();
}
Syst
You can't alter the start time, but you can modify it after the Stop() and no one is the wiser.
A quick Google search: http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.start(v=vs.90).aspx
A minor modification:
class Program
{
static void Main(string[] args)
{
System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
stopWatch.Start();
Thread.Sleep(10000);
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes + 45 , ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine("RunTime " + elapsedTime);
}
}
Result:
RunTime 00:45:10.00
Press any key to continue . . .
A little more research on your part will help you immeasurably as a developer.