- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to read a line from the console in C#?
The ReadLine() method is used to read a line from the console in C#.
str = Console.ReadLine();
The above will set the line in the variable str.
Example
using System; using System.Collections.Generic; class Demo { static void Main() { string str; // use ReadLine() to read the entered line str = Console.ReadLine(); // display the line Console.WriteLine("Input = {0}", str); } }
Output
Input =
Above, we displayed a line using the Console.ReadLine() method. The string is entered by the user from the command line.
Advertisements