mert
mert

Reputation: 153

Set variable inside void function

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);
    }
}

Upvotes: -1

Views: 63

Answers (1)

Ted
Ted

Reputation: 4067

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;

Upvotes: 1

Related Questions