我正在写一个名为Food的课程.我考虑了一个字段"int cookingTime"来查看这个类的每个实例已存在多长时间.我以为我应该使用Timer类.我写了下面的一段代码,但它没有用.我不确定我的方法是否正确.我非常感谢任何帮助.
Class Food
{
private System.Timers.Timer timerClock = new System.Timers.Timer();
static int cookingTime = 0;
public Food()
{
this.timerClock.Elapsed += new System.Timers.ElapsedEventHandler(process);
this.timerClock.Interval = 1000;
this.timerClock.Enabled = true;
}
static void process(Object myObject, EventArgs myEventArgs)
{
cookingTime += 1;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
83 次 |
| 最近记录: |