Reader Level:
ARTICLE

Creating C# Console Application using a Text Editor

Posted by Sandeep Shekhawat Articles | Visual C# June 03, 2011
Here I show steps to create console application using a text editor and compiling from a command window.
  • 0
  • 0
  • 11788

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.

texteditor1.jpg 
 
Fig 1. Control Panel Home

3. A new window System Properties opens. Click on the Advanced Tab and click on Environment Variables. 

texteditor2.jpg
  
Fig 2 System Properties

4. A new window for Environment Variables opens. 

texteditor3.jpg
 
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

texteditor4.jpg
 
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.

texteditor5.jpg 

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 

texteditor6.jpg 

Fig 6 Output

Article Extensions
Contents added by Suthish Nair on Jun 04, 2011

For Windows XP users...

C:\Windows\Microsoft.NET\Framework64\v3.5 ==> C:\WINDOWS\Microsoft.NET\Framework\v3.5

Point 7. After choosing above directory through command prompt then enter csc

Point 9. Save to a folder. e.g. C:\HelloWorld.cs

    Now back to command prompt. Run the csc command with File path.
      
            e.g. C:\WINDOWS\Microsoft.NET\Framework\v3.5> csc C:\HelloWorld.cs

    Now open the folder C:\WINDOWS\Microsoft.NET\Framework\v3.5 you can see HelloWorld.exe.

            Double Click on it for output. Remember to have System.Console.ReadLine();.


Thank You !

   

COMMENT USING

Trending up