我怎样才能使这个简单的 for 循环 运行 每秒?
How can i make this simple for loop run every second?
这是一个简单的计时器,从用户设置的值开始,倒数到 0
namespace SuperSimpleTimer
{
class Program
{
static void Main(string[] args)
{
//This makes the loop starts from a user inserted value
myTime = int.Parse(Console.ReadLine());
for (int i = myTime; i >= 0; i--)
{
// clears the old value and Writes the new one
//Console.Clear();
Console.WriteLine(i);
}
Console.ReadLine();
}
}
}
最简单的方法是:
Thread.Sleep(1000);
应该这样应用:
using System.Threading;
namespace SuperSimpleTimer
{
class Program
{
static void Main(string[] args)
{
//This makes the loop starts from a user inserted value
myTime = int.Parse(Console.ReadLine());
for (int i = myTime; i >= 0; i--)
{
// clears the old value and Writes the new one
//Console.Clear();
Console.WriteLine(i);
Thread.Sleep(1000); //1000(ms) = 1 second
}
Console.ReadLine();
}
}
}
这是一个简单的计时器,从用户设置的值开始,倒数到 0
namespace SuperSimpleTimer
{
class Program
{
static void Main(string[] args)
{
//This makes the loop starts from a user inserted value
myTime = int.Parse(Console.ReadLine());
for (int i = myTime; i >= 0; i--)
{
// clears the old value and Writes the new one
//Console.Clear();
Console.WriteLine(i);
}
Console.ReadLine();
}
}
}
最简单的方法是:
Thread.Sleep(1000);
应该这样应用:
using System.Threading;
namespace SuperSimpleTimer
{
class Program
{
static void Main(string[] args)
{
//This makes the loop starts from a user inserted value
myTime = int.Parse(Console.ReadLine());
for (int i = myTime; i >= 0; i--)
{
// clears the old value and Writes the new one
//Console.Clear();
Console.WriteLine(i);
Thread.Sleep(1000); //1000(ms) = 1 second
}
Console.ReadLine();
}
}
}