Read information from Console - CSharp Language Basics

CSharp examples for Language Basics:Console

Description

Read information from Console

Demo Code

using System;//w  w w .jav  a  2  s .c o  m
using System.Text;
class ReadIt
{
   public static void Main()
   {
      StringBuilder Input = new StringBuilder();
      int ival;
      char ch = ' ';
      Console.WriteLine("Enter text. When done, press CTRL+Z:");
      while ( true )
      {
         ival = Console.Read();
         if ( ival == - 1 )
            break;
         ch = ( char ) ival;
         Input.Append(ch);
      }
      Console.Write( Input );
   }
}

Result


Related Tutorials