.NET Development Foundation/Hello world

From Wikibooks, open books for an open world
Jump to: navigation, search

System types and collections: Hello world example

Hello world example[edit]

    using System;
    using System.Collections.Generic;
    using System.Text;
namespace HelloWorldLab1
    class Program
        static void Main(string[] args)
            Console.WriteLine("Hello world!");
            Console.WriteLine("Press ENTER to exit");

Note: when you create a new console project in Visual studio, all the code is generated by default except for the 3 "Console" lines in the Main method. Just add those 3 lines and run the program.

We have discussed all the parts of that program except for the role of the Console which will be discussed in the input/output section (Stream). For now, lets say that it is a System class, in the System namespace (the "using System" instruction makes the "System." part of "System.Console.Writeline()" optional) and that the WriteLine() and ReadLine() methods write and read strings to and from the console.