Compiling HelloWorld in C# using CSC
CSC is the C# compiler that comes with .NET and is really simple to use to compile your programs with. Make sure you have the latest .NET version installed before reading on.
Fire up your code editor of choice (even notepad will do) and create your program, e.g. HelloWorld:
using System;
public class HelloWorld
{
public static void Main()
{
Console.WriteLine("Hello World");
}
}
and save the file out as a .cs file for example HelloWorld.cs
Load up a command prompt (start->run, type 'cmd' without the '' and hit enter). Navigate to C:\Windows\Microsoft.NET\Framework\v4.0.30319 by typing:
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
where v4.0.30319 is the folder name of the latest version of .NET you have installed.
The compiler executable csc.exe can be found in this folder, and all you have to do next is type
csc c:\path\to\HelloWorld.cs
where c:\path\to\HelloWorld.cs is the location you saved your code to. This will produce HelloWorld.exe in the csc folder which you can test by typing
HelloWorld.exe
assuming you are still in the csc directory under your command prompt.
2011-05-23 19:43:59