Console.Read Method In C#

In this article, I will explain you about Console.Read method in C#.
  • 4443

Introduction

Console programs are very easy to develop. Console programs read input and write output. For reading purpose we can use Console.Read method. Console.Read method reads the next character from the standard input stream in the console window, when we press enter it returns as an int.

Example 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication11

{

    class Program

    {

        static void Main(string[] args)

        {

            // Write to console window.

            int s;

            Console.WriteLine("----------------Enter your name---------------");

            s = Console.Read();

            Console.WriteLine("My name is:{0}", s);

            Console.ReadKey();

        }

    }

}

 

The output of following program

Clipboard210.jpg

© 2013 dotNetheaven. All rights reserved.