4.1 How to compile and run the code examples in this book


If you have VS .NET, you can choose either to write and compile the codes within the VS .NET IDE, or via command line.

You cannot run the VS .NET command line tools from your usual Windows DOS prompt (which is activated by START run, type in "cmd" or START Programs Accessories Command Prompt ) because certain configuration settings are required.

You need to use the special VS .NET command prompt if you want to use the command line tools. After you have installed VS .NET, click on START Programs Microsoft Visual Studio .NET Visual Studio .NET tools Visual Studio Command Prompt .

Type in your codes using a text editor (e.g. Notepad) and compile it using the command line C# compiler csc.exe like this:

 c:\expt>csc HelloWorld.cs 

Capitalization of the file name here doesn't matter. C# is case sensitive, but not at command line. If everything goes smoothly, HelloWorld.exe will be generated. HelloWorld.exe contains IL codes and is what is called a .NET assembly.

Figure 4.1 shows what happens during compilation.

Figure 4.1. Compilation into IL.

graphics/04fig01.gif

To run the program, you can either type in the full file name (i.e. HelloWorld.exe ) or simply HelloWorld :

 c:\expt>HelloWorld 

The output is:

 c:\expt>C#! Here I come! 

Figure 4.2 shows what happens during runtime.

Figure 4.2. Runtime JIT-compilation.

graphics/04fig02.gif

The screen output in this exercise is shown in Figure 4.3.

Figure 4.3. Compiling and running Helloworld.cs

graphics/04fig03.gif



From Java to C#. A Developers Guide
From Java to C#: A Developers Guide
ISBN: 0321136225
EAN: 2147483647
Year: 2003
Pages: 221
Authors: Heng Ngee Mok

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net