我正在开发一个愚蠢的小终端应用程序,它显示当前时间以及用户下班的时间。我有一个小问题。在“工作退出时间”是静态的之前,我将其设置为下午 6:00:00,我试图接受它并允许用户输入主题。现在我的代码可以获取变量集。但是我不能将它 [WorkOut 的变量] 放在我想要它去的地方。
这是我到目前为止所拥有的:
namespace timerconsole
{
class MainClass
{
public void run ()
{
int width = 35;
int height = 10;
Console.SetWindowPosition(0, 0);
Console.SetWindowSize(width, height);
Console.SetBufferSize(width, height);
Console.SetWindowSize(width, height);
Console.WriteLine ("What time do you leave work today: ");
String workTime = Console.ReadLine ();
int workOut;
int.TryParse (workTime, out workOut);
TimerCallback callback = new TimerCallback(Tick);
// create a one second timer tick
Timer stateTimer = new Timer(callback, null, 0, 1000);
// loop here forever
for (; ; ) { }
}
static public void Tick(Object stateInfo)
{
Console.Clear ();
Console.WriteLine("The time is: {0}", DateTime.Now.ToString("h:mm:ss") + "\nWork Target: {0}", workOut); // workOut is my issue. It says "workOut does not exist in current context"
}
public static void Main (string[] args)
{
MainClass tc = new MainClass ();
tc.run ();
}
}
}