Problem : You are declaring your startTime
and endTime
variables inside the functions as below:
public void start()
{
DateTime startTime = DateTime.Now; //remove the declartion from here
}
public void end()
{
DateTime startTime = DateTime.Now; //remove the declaration from here
}
Solution : Declare your startTime
and endTime
variables as class variables and then assign the values in the start()
and end()
functions.
Try This:
DateTime startTime; //declare here
DateTime endTime; //declare here
public void start()
{
startTime = DateTime.Now; //assign value here
}
public void end()
{
endTime = DateTime.Now; //assign value here
}