How to read a value from Console?

Introduction

This article explains how to get an input from the console. If you have used C++ then cin and cout are the functions for read and write to the console.

Type this code in a text editor and save file as read.cs.

using System;

class ReadStr
{
    public static void Main()
    {
        Console.Write("Enter your name: ");
        string szName = Console.ReadLine();
        Console.WriteLine("Hey " + szName);
    }
}

Now compile it from command line with syntax cs read.cs. It will create an exe, read.exe in same dir where your read.cs file is. Run the exe.

Note. I like to use my VC++ editor to create a text file and save it as .cs extension.


Similar Articles
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.