I am very new to c# and i want to learn it......is there is a good tutorial to learn visual c# 2010 express for desktop apllication.
And I wanted to to create a code(c#)to display total elasped time as a label when the user clicks an evaluate button (add or subtact from the current elasped time to evaluate elasped time)....please somebody help me

Recommended Answers

All 5 Replies

There are lots of good tutorials out there, google will provide many.

As for your elapsed time question, there are a number of ways to do this but here is the way I like to handle it:

// remember the time at the start
DateTime start = DateTime.Now;
// do your work
Evaluate();
// get the time at the end
DateTime end = DateTime.Now;
// DateTime objects can be subtracted or compared
TimeSpan duration = end - start;
// build a string explaining the time elapsed
string timeElapsed =  String.Format("{0} Hours, {1} Minutes, {2} Seconds", Math.Floor(duration.Hours), Math.Floor(duration.Minutes), Math.Floor(duration.Seconds);
// update a label with the time elapsed string
label.Text = timeElapsed;

public void Evaluate()
{
  // do something here...

}

Hope this helps.

I like to use the Stopwatch class for timing things.

commented: Excellent :) +11

There are lots of good tutorials out there, google will provide many.

As for your elapsed time question, there are a number of ways to do this but here is the way I like to handle it:

// remember the time at the start
DateTime start = DateTime.Now;
// do your work
Evaluate();
// get the time at the end
DateTime end = DateTime.Now;
// DateTime objects can be subtracted or compared
TimeSpan duration = end - start;
// build a string explaining the time elapsed
string timeElapsed =  String.Format("{0} Hours, {1} Minutes, {2} Seconds", Math.Floor(duration.Hours), Math.Floor(duration.Minutes), Math.Floor(duration.Seconds);
// update a label with the time elapsed string
label.Text = timeElapsed;

public void Evaluate()
{
  // do something here...

}

Hope this helps.

thanks for ur help darkagn, but it is showing an error as "the call is ambigious between the following methods or properties; 'System.Math.Floor(double)' and 'System.Math.Floor(decimal)'....will you please help me....

Use TotalHours, TotalMinutes, and TotalSeconds properties.

...
string timeElapsed =  String.Format("{0} Hours, {1} Minutes, {2} Seconds", Math.Floor(duration.TotalHours), Math.Floor(duration.TotalMinutes), Math.Floor(duration.TotalSeconds);
....

Use TotalHours, TotalMinutes, and TotalSeconds properties.

...
string timeElapsed =  String.Format("{0} Hours, {1} Minutes, {2} Seconds", Math.Floor(duration.TotalHours), Math.Floor(duration.TotalMinutes), Math.Floor(duration.TotalSeconds);
....

Thanks a lot :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.