
- 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
Way to read input from console in C#
Use the ReadLine() method to read input from the console in C#. This method receives the input as string, therefore you need to convert it.
For example −
Let us see how to get user input from user and convert it to integer.
Firstly, read user input −
string val; Console.Write("Enter integer: "); val = Console.ReadLine();
Now convert it to integer −
int a = Convert.ToInt32(val); Console.WriteLine("Your input: {0}",a);
Let us see this in an example. The input is added using command line argument−
Example
using System; using System.Collections.Generic; class Demo { static void Main() { string val; Console.Write("Enter Integer: "); val = Console.ReadLine(); int a = Convert.ToInt32(val); Console.WriteLine("Your input: {0}",a); } }
The above will give the following result −
Enter Integer: 5 Your input: 5
- Related Articles
- Ways to read input from console in Java
- Python program to read input from console
- How to read a line from the console in C#?
- Read integers from console in Java
- Taking input from console in Python
- How to read data from user using the Console class in Java?
- How to read data from PDF file and display on console in Java?
- Haskell program to read numbers from standard input
- Get number from user input and display in console with JavaScript
- Java Program to Read The Number From Standard Input
- Kotlin Program to Read The Number From Standard Input
- How to change the Input Encoding Scheme of the C# Console?
- How to Read The Number From Standard Input in Swift Program?
- How to get the Standard Input and Output Stream through Console in C#?
- How can we read from standard input in Java?

Advertisements