How to print 1 to 100 without any looping using C#

后端 未结 28 1432
天命终不由人
天命终不由人 2020-12-22 19:30

I am trying to print numbers from 1 to 100 without using loops, using C#. Any clues?

28条回答
  •  北海茫月
    2020-12-22 20:04

    class Program
    {
        static Timer s = new Timer();
        static int i = 0;
        static void Main(string[] args)
        {
            s.Elapsed += Restart;
            s.Start();
            Console.ReadLine();
        }
        static void Restart(object sender, ElapsedEventArgs e)
        {
            s.Dispose();
            if (i < 100)
            {
                Console.WriteLine(++i);
                s = new Timer(1);
                s.Elapsed += Restart;
                s.Start();
            }
        }
    }
    

    You must notice that I'm NOT using recursion.

提交回复
热议问题