Reading an integer from user input

后端 未结 11 777
时光取名叫无心
时光取名叫无心 2020-11-22 09:44

What I am looking for is how to read an integer that was given by the user from the command line (console project). I primarily know C++ and have started down the C# path. I

11条回答
  •  伪装坚强ぢ
    2020-11-22 10:13

    static void Main(string[] args)
        {
            Console.WriteLine("Please enter a number from 1 to 10");
            int counter = Convert.ToInt32(Console.ReadLine());
            //Here is your variable
            Console.WriteLine("The numbers start from");
            do
            {
                counter++;
                Console.Write(counter + ", ");
    
            } while (counter < 100);
    
            Console.ReadKey();
    
        }
    

提交回复
热议问题