A simple command line program that reads from the console using Console.Read() and Console.ReadLine() : Console Input Output « Development Class « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Class Interface
3. Collections Data Structure
4. Components
5. Data Types
6. Database ADO.net
7. Design Patterns
8. Development Class
9. Event
10. File Stream
11. Generics
12. GUI Windows Form
13. Language Basics
14. LINQ
15. Network
16. Office
17. Reflection
18. Regular Expressions
19. Security
20. Services Event
21. Thread
22. Web Services
23. Windows
24. XML
25. XML LINQ
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorial
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / C Sharp » Development Class » Console Input OutputScreenshots 
A simple command line program that reads from the console using Console.Read() and Console.ReadLine()
A simple command line program that reads from
    the console using Console.Read() and Console.ReadLine()

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/

/*
    read.cs. A simple command line program that reads from
    the console using Console.Read() and Console.ReadLine().

    Compile this program using the following line:
        C:>csc read.cs
 */

using System;
public class ReadCmdLine
{
    static void Main()
    {
        Console.WriteLine ("First, using the Read() function " +
                           "without clearing the buffer");
        int arg;
        Console.Write("Type one or more characters: ");
        while ((arg = Console.Read()) 10)
        {
            if (arg == 13)
                Console.WriteLine (" <EOL>");
            else
                Console.Write (Convert.ToChar(arg));
        }
        Console.WriteLine();
        Console.WriteLine ("Now, using the Read() function and " +
                           "clearing the buffer");
        Console.Write("Type one or more characters: ");
        arg = Console.Read ();
        string str = Console.ReadLine();
        Console.WriteLine ("The character is " + Convert.ToChar(arg));
    }
}

           
       
Related examples in the same category
1. Read double and int from console
2. Read a character from the keyboardRead a character from the keyboard
3. Input from the console using ReadLine()Input from the console using ReadLine()
4. Read a string from the keyboard, using Console.In directlyRead a string from the keyboard, using Console.In directly
5. Write to Console.Out and Console.ErrorWrite to Console.Out and Console.Error
6. Output with parameters
7. Illustrates how to read a character entered using the keyboardIllustrates how to read a character entered using the keyboard
8. Illustrates how to read a string entered using the keyboardIllustrates how to read a string entered using the keyboard
9. Read a line from consoleRead a line from console
10. Demonstrates redirecting the Console output to a fileDemonstrates redirecting the Console output to a file
11. Console command-line argumentsConsole command-line arguments
12. Use format commandsUse format commands
13. Redirect Console.OutRedirect Console.Out
14. This program averages a list of numbers entered by the userThis program averages a list of numbers entered by the user
15. Demonstrate various format specifiersDemonstrate various format specifiers
16. While loop and keyboard readingWhile loop and keyboard reading
17. Demonstrates some of the formatting flags for writing text to the consoleDemonstrates some of the formatting flags for writing text
               to the console
18. Uses the #, 0 and comma characters to format outputUses the #, 0 and comma characters to format output
19. C# Basic Data TypesC# Basic Data Types
20. C# Hello UniverseC# Hello Universe
21. Terminate a control input
22. Use do while to read console input
23. Use while(true) to read console input
24. Convert input from control to upper case
25. constructs sentences by concatenating user input until the user enters one of the termination characters
26. input a series of numbers separated by commas, parse them into integers and output the sum
ww_w__.__jav___a2___s__.c_o___m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.