C#: The Main function

This entry is part 12 of 71 in the series C#

The Main method is the entry point of a C# console application or windows application. 

When the application is started, the Main method is the first method that is invoked.

using System;

namespace Hello
    class Program
        static void Main()
            string name;

            Console.WriteLine("Hello, what is your name?");
            name = Console.ReadLine();
            Console.WriteLine("Your name is " + name);

Main must be static and it should not be public.

Static members are not tied to class instances.  Rather, they can be called without having an instance.

For example, to access the Review method, we create an instance called book.

Book book = new Book();

Now for the Main method, we do not have to create an instance to access it.  It will be invoked first and will be done so automatically.


Series Navigation<< C#: Reading input using Readline()
C#: The dot operator >>