Changes

Jump to: navigation, search

A Simple C Sharp Console Application

657 bytes added, 21:13, 9 January 2008
no edit summary
In the early 1970's the creators of the C Programming Language wrote a book of the same name intended to teach the skills necessary to program in C. One of the first chapters of this book contained a very simple C program which simply displayed the words "Hello World" in a console. Ever since that day most programming books has followed this tradition. Given that C# can trace its ancestry to the C programming language [[C Sharp Essentials|C# Essentials]] will be no exception to this rule.
Even if you are an experienced programmer this simple C# example is still recommended if only to verify that the C# development environment is correctly installed.
<pre>
Set PATH=%PATH%;%Windir%\Microsoft.NET\Framework\v3.5
</pre>
 
If you are running on a non-Windows system such as Linux you will need to use either Mono or DotGNU. The Mono compiler command is ''mcs''.
 
== Creating a Sample C# Program ==
 
Once the appropriate environment is installed and configured the next step is to write our ''Hello World'' example. Convention dictates that C# sources files be named with the .cs file name extension. We shall, therefore, name our example file HelloCsharp.cs. Using your favorite code editor create the following C# source code:
 
<pre>
class HelloCsharp
{
static void main()
{
System.Console.WriteLine ("Hello from C#.");
}
}
</pre>

Navigation menu