TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to C-SHARP

C# Console.Read Method

Use the Console.Read method. Write the output of Console.Read in a terminal window.
Console.Read reads in characters from the console. It returns, as an integer, each value until a zero is reached. This signifies the end of the user's input. It should be called in a loop to get all the buffered characters.
Example. We look at a console program written in the C# language. It is intended to demonstrate the exact behavior of the Console.Read public static method when used in a while-loop in a terminal window.While

Note: When the Read method is first called, it blocks execution waiting for the input to be sent by the terminal window.

Finally: It returns when the input is final. Then, you must call it in a loop to read the entire remaining buffer.

Example: The conditional expression here continues until zero is received from Console.Read—this occurs at the end of the input.

WriteLine: The program outputs the integer representation and the character representation of each value in the buffer.

ConsoleEnvironment.NewLine
C# program that uses Console.Read method using System; class Program { static void Main() { // This program accepts console input. // ... When the enter key is pressed, // the Read method returns the first time. // ... Then, each call to Read accesses one // further character from the input. int result; while ((result = Console.Read()) != 0) { Console.WriteLine("{0} = {1}", result, (char)result); } } } Output dotnetCodex 100 = d 111 = o 116 = t 110 = n 101 = e 116 = t 112 = p 101 = e 114 = r 108 = l 115 = s 13 = 10 =
Notes, Read. If you just need one character, skip the loop. Read does not return until the input is final and the user presses the enter key. For most programs that require strings from the terminal, please consider the Console.ReadLine method.Console.ReadLine
Summary. We looked at the Console.Read method. We applied it in a program that prints the exact terminal buffer contents. This method is normally used in a loop in console programs that can accept more than one character.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf