A Simple “Hello User” Program

Let's get right down to business. The following program displays a greeting to the console:

// Project HelloUser

class MyApp
{
     public static void Main() {
       System.String userName = "Jay";
       System.Console.WriteLine("Hello " + userName);
     }
}

This simple application defines a class called MyApp that has a single static public method called Main. Under .NET, methods must generally be members of a class or a struct. A class or a struct form the basic unit of organization under .NET and are generally referred to as types. We explore the differences between a class and a struct in detail in Chapter 4.

Static method Main is considered the entry point for the program. When the program is run, the .NET runtime starts executing ...

Get .NET Programming: A Practical Guide Using C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.