Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

want a timer?

In my quest to understand C#(see the "Current System Time?" post), I've
written a little toy snippet that I think I'll use to time my code(below
with driver). I wonder if:

1)any fellow neophytes might find it useful
2)any pros could comment on better ways to write this, improvements that
could be educational to write
3)anyone could flame me if I'm not supposed to post code, or if this is one
of those things I should keep to myself

namespace bigOscar {
using Date = System.DateTime;
using Span = System.TimeSpan;

public class timer {
private Date startDt= new Date();
private Date endDt = new Date();

public void start() {
startDt = Date.Now;
}

public void stop() {
endDt = Date.Now;
}

public override string ToString() {
Span diff = endDt - startDt;
return(diff.ToString());
}
}
}

public class timerDriver {
public static void Main() {
bigOscar.timer t = new bigOscar.timer();
t.start();

//code to time

t.stop();
System.Console.WriteLine(t);
}
}
[1147 byte] By [Oscar] at [2007-11-9 18:21:27]