C# equivalent to Java's scn.nextInt( )

前端 未结 3 637
甜味超标
甜味超标 2021-02-11 08:12

In Java, if we want to read an user input from the console, we can do the following.

Scanner scn = new Scanner (System.in);
int x;

x = scn.nextInt();  //Receive         


        
3条回答
  •  无人及你
    2021-02-11 09:00

    Is it equivalent to Java's scanner.nextInt() when I use int a = int.Parse(Console.ReadLine()); to receive int inputs?

    Yes. Java's Scanner.nextInt() throws an exception when no integer input has been received, as does .NET's int.Parse(Console.ReadLine()).

提交回复
热议问题