A Simple C# Program

by Dinesh 2012-07-22 20:13:05

Using your favorite code editor create the following C# source code:

A Simple Welcome Program: Welcome.cs

// Namespace Declaration
using System;

// Program start class
class WelcomeCSS
{
// Main begins program execution.
static void Main()
{
// Write to console
Console.WriteLine("Welcome to the C# Station Tutorial!");
}
}

The program in Listing has 4 primary elements, a namespace declaration, a class, a Main method, and a program statement. It can be compiled with the following command line:

csc.exe Welcome.cs

This produces a file named Welcome.exe, which can then be executed. Other programs can be compiled similarly by substituting their file name instead of Welcome.cs. For more help about command line options, type "csc -help" on the command line. The file name and the class name can be totally different.

Note for VS.NET Users: The screen will run and close quickly when launching this program from Visual Studio .NET. To prevent this, add the following code as the last line in the Main method:

// keep screen from going away
// when run from VS.NET
Console.ReadLine();

Tagged in:

1023
like
0
dislike
0
mail
flag

You must LOGIN to add comments