
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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.
- Related Articles
- Way to read input from console in C#
- Read integers from console in Java
- Ways to read input from console in Java
- How to read data from user using the Console class in Java?
- Python program to read input from console
- How to print a line on the console using C#?
- How to read a Specific Line From a File in Linux?
- How to read data from PDF file and display on console in Java?
- How to read a file from command line using Python?
- Read Random Line From a File in Linux
- C# Program to Read the Content of a File Line by Line
- How to read an entire line from a text file using Python?
- How to stop C++ console application from exiting immediately?
- Read last line from file in PHP
- How to clear console in C?

Advertisements