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

后端 未结 28 1540
天命终不由人
天命终不由人 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:17

    namespace ConsoleApplication2 {
        class Program {
            static void Main(string[] args) {
                Print(Enumerable.Range(1, 100).ToList(), 0);
                Console.ReadKey();
    
            }
            public static void Print(List numbers, int currentPosition) {
                Console.WriteLine(numbers[currentPosition]);
                if (currentPosition < numbers.Count - 1) {
                    Print(numbers, currentPosition + 1);
                }
            }
        }
    }
    

提交回复
热议问题