该课程不会使用 Speedrun.AddToTime(h, m, s) 添加到秒表时间
不知道为什么!
class Speedrun
{
private static Stopwatch sr = new Stopwatch();
public static void Go()
{
sr.Reset();
sr.Start();
}
public static string GetTime
{
get
{
return sr.Elapsed.Hours + "h " + sr.Elapsed.Minutes + "m " + sr.Elapsed.Seconds + "s";
}
}
public static void AddToTime(int hours, int minutes, int seconds)
{
TimeSpan ts = new TimeSpan(hours, minutes, seconds);
sr.Elapsed.Add(ts);
}
public static void Stop()
{
sr.Stop();
}
public static void Cont()
{
sr.Start();
}
}
相当直截了当,我使用类名本身而不是变量来引用它。如此处所见
Speedrun.Go();
任何帮助将不胜感激!
更新!!
在这里找到的廉价解决方案是为了帮助可能有类似情况的人
class Speedrun
{
private static Stopwatch sr = new Stopwatch();
private static int addedhours = 0;
private static int addedminutes = 0;
private static int addedseconds = 0;
public static void Go()
{
sr.Reset();
sr.Start();
addedhours = 0;
addedminutes = 0;
addedseconds = 0;
}
public static string GetTime
{
get
{
return (sr.Elapsed.Hours + addedhours) + "h " + (sr.Elapsed.Minutes + addedminutes) + "m " + (sr.Elapsed.Seconds + addedseconds) + "s";
}
}
public static void AddToTime(int hours, int minutes, int seconds)
{
addedhours = addedhours + hours;
addedminutes = addedminutes + minutes;
addedseconds = addedseconds + seconds;
}
public static void Stop()
{
sr.Stop();
}
public static void Cont()
{
sr.Start();
}
}