
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Read Inputs as Strings in C#
To read inputs as strings in C#, use the Console.ReadLine() method.
str = Console.ReadLine();
The above will read input as string. You don’t need to use the Convert method here since the input takes string by default.
Now display the string entered by user −
Example
using System; using System.Collections.Generic; class Demo { static void Main() { string myStr; // use ReadLine() to read the entered line myStr = Console.ReadLine(); // display the line Console.WriteLine("Result = {0}", myStr); } }
Output
Result =
The following is the output. Let’s say the user entered “Amit” as the input −
Result = amit
Advertisements