How to read inputs as strings in C#?

CsharpProgrammingServer Side Programming

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 −


 Live Demo

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);


Result =

The following is the output. Let’s say the user entered “Amit” as the input −

Result = amit
Published on 20-Aug-2018 10:16:23