我需要启动一个秒表,然后在另一个类中停止它,然后检索已经过去的时间。当我在OnSignIn方法中创建秒表对象时,它看不到方法中对象的创建OnSignOut。我应该如何解决这个问题?
public void OnSignIn(int pin)
{
if (this.pin == pin && this.SignIn == false)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
}
else if (this.pin != pin)
{
MessageBox.Show("Incorrect pin or already logged in");
}
}
public void OnSignOut (int pin)
{
if (this.pin == pin && this.SignIn == true)
{
stopwatch.Stop();
}
else
{
MessageBox.Show("Error!");
}
}
Run Code Online (Sandbox Code Playgroud) c# ×1