Creating C# Console Application using a Text Editor

We can develop a C# standalone program or console application using an Integrate Development Environment (IDE) like Visual Studio or using a plain text editor like Notepad, Wordpad etc. The following shows how to do that using a text editor for a simple "Hello World" program. First of all set the path for the C# Compiler (using Windows 7).
 
1. Right-click Computer and click on Properties from Drop-Down Pane.
 
2. Now Control Panel Home open and click on Advanced system settings.
 
 
Fig 1. Control Panel Home
 
3. A new window System Properties opens. Click on the Advanced Tab and click on Environment Variables. 
 
  
Fig 2 System Properties
 
4. A new window for Environment Variables opens. 
 
 
Fig 3 Environment Variable
 
5. There are two parts:
  • User variables
  • System variables    
Under the User variables Pane click on the New button. A window New User Variable opens; it has two parameters:
  • Variable name 
  • Variable value
In the Variable name write path. For the Variable value write the C# compiler path, such as: 
C:\Windows\Microsoft.NET\Framework64\v3.5
 
 
Fig 4 New User Variable
 
6. In the New User Variable Window click the OK button then for the Environment Variables window click the OK button then for the System Properties window click the OK button.
 
7. Open a Command Prompt and type in the command csc and press ENTER.
 
If following prompt appears then that means your C# compiler 3.5 path is correct.
 
Fig 5 Path Varification
 
8. Type the following code with any Text Editor (Notepad, WordPad, etc):
 
class HelloWorld
 {
static void Main()
 {
System.Console.Write("Hello World");
 }
  }
 
9. Save the file at any location of the hard drive with class name and .cs extension. Open a Command Prompt window and compile HelloWorld.cs class using following command:
 
csc file-name 
 
for example csc HelloWorld.cs 
 
After successful compilation the HelloWorld.cs file's executable file HelloWorld.exe is created; now run this .exe file using the following command:
filename
 
for example HelloWorld.exe
 
Or 
 
HelloWorld
 
Now our output is 
 
 
Fig 6 Output


Similar Articles