c#如何令数组里面的元素不停地循环在屏幕上,然后按空格键停止,按回车就继续呢?
1个回答
展开全部
//using System.Timers;
class Program
{
static int index = 0;
static int[] nums = { 11, 22, 33, 44, 55 };
static int len = nums.Length;
static Timer t = new Timer(200);
static void Main(string[] args)
{
t.Elapsed += (s, e) =>
{
Console.WriteLine(nums[index++ % len]);
};
t.Start();
while (true)
{
var ck = Console.ReadKey(false);
//Console.WriteLine(ck.Key.ToString());
if (ck.Key.ToString() == "Spacebar")
{
t.Stop();
}
else if (ck.Key.ToString() == "Enter")
{
t.Start();
}
System.Threading.Thread.Sleep(50);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询