Basic Input and Output with the Console Class

In addition to the members in Table 3-2, the Console type defines a set of methods to capture input and output, all of which are shared and are therefore called by prefixing the name of the class (Console) to the method name. As you have seen, WriteLine() pumps a text string (including a carriage return) to the output stream. The Write() method pumps text to the output stream without a carriage return. ReadLine() allows you to receive information from the input stream up until the carriage return, while Read() is used to capture a single character from the input stream.

To illustrate basic I/O using the Console class, create a new Console Application named BasicConsolelO and update your Main() method with logic that prompts the user for some bits of information and echoes each item to the standard output stream.

Sub Main()

Console.WriteLine("***** Fun with Console IO *****") ' Echo some information to the console.

Console.Write("Enter your name: ") Dim s As String = Console.ReadLine() Console.WriteLine("Hello, {0}", s)

Console.Write("Enter your age: ") s = Console.ReadLine()

Console.WriteLine("You are {0} years old", s) End Sub

Was this article helpful?

0 0

Post a comment