Set variable inside void function

Viewed 46

When I press the button, I want to assign the current time (start temp value) to the start time variable in the same class. How can i make it?

public class Simulator
{
TimeSpan start Time;
    private void b_start_Click(object sender, EventArgs e)
    {
       string tempDate = DateTime.Now.ToString("h:mm:ss");
       TimeSpan startTemp = TimeSpan.Parse(tempDate);
    }
}
1 Answers

Instead of:

TimeSpan startTemp = TimeSpan.Parse(tempDate);

You can assign to the class member directly:

this.startTime = TimeSpan.Parse(tempDate);

Your member declaration seems to be incorrect...

TimeSpan startTime;
Related