小编Dan*_* V.的帖子

我可以用一种方法启动秒表,然后用另一种方法停止同一个秒表吗?并检索经过的时间?

我需要启动一个秒表,然后在另一个类中停止它,然后检索已经过去的时间。当我在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#

0
推荐指数
1
解决办法
230
查看次数

标签 统计

c# ×1