Getting Input from User / Keyboard in C#

(Last Updated On: January 29, 2019)

Getting Input from User / Keyboard in C# – Learn how to get input from user / keyboard like int, string and double data types etc in C# program. Example of taking integer / string input using Console.ReadLine method in C#.

To get the input from user, we use predefined Console.ReadLine method.

  • Console.ReadLine-Read complete string including spaces.
  • Console.Read – reads a character and returns an ASCII integer value for the input character.
  • Console.ReadKey-reads a character and returns that character.



How to take integer input from user in C#

C# Code



Reading a string input from User in C#

In this section, you will learn how to take string input using Console.ReadLine in C# program. To read a string / sentence from the user we use ReadLine method of Console class.

C# Code

Enter Your Name:
Viswanath Annangi
You entered your name as Viswanath Annangi


Reading Two Integers input from user in C#

Below program read two integers from user one by one. It prompt user to integer first and second number. The program displays the sum of both numbers entered by user. It will display the output as below


Enter first integer:
Enter Second integer:
Sum :50