To write lines of text to the console window, you must access the ‘Console’ class object. You do this by typing ‘Console’ and then a period ‘.’ to access its methods and properties. You use the ‘WriteLine()’ method which can accept a string as an argument, such as “Hello user.”
1: Module SimpleConsole
2:
3: Sub Main()
4:
5: ' Write a line to the console window.
6: Console.WriteLine("Hello user.")
7:
8: ' Wait for the user to press enter before exiting.
9: Console.ReadLine()
10:
11: End Sub
12:
13: End Module
1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Text;
5:
6: namespace SimpleConsole
7: {
8: class Program
9: {
10: static void Main(string[] args)
11: {
12:
13: // Write a line to the console window.
14: Console.WriteLine("Hello user.");
15:
16: // Wait for the user to hit enter before exiting.
17: Console.ReadLine();
18: }
19: }
20: }
The above example will produce the following result:
No comments:
Post a Comment