April 2002
Intermediate to advanced
1024 pages
23h 26m
English
One of your first tasks in learning C# is to create a C# program. Listing A.1 shows a simple C# program that simply prints a message to the Console.
using System;
namespace Hello
{
class HelloMain
{
static void Main(string[] args)
{
Console.WriteLine("Hello!");
}
}
}
|
First, notice that a namepace encloses the entire program. This is strictly not required. If the namespace is taken out, leaving the class HelloMain, the program would still compile and run. However, it is a good idea to get in the habit of enclosing your programs with a namespace. This prevents conflicts with other modules and libraries.
Classes can only exist directly in a namespace. You cannot put methods or fields directly ...
Read now
Unlock full access