Книга: C# 2008 Programmer

Using the C# Compiler (csc.exe)

Using the C# Compiler (csc.exe)

Besides using Visual Studio 2008 to compile and run the application, you can build the application using Visual Studio 2008 and use the C# compiler (csc.exe) to manually compile and then run the application. This option is useful for large projects where you have a group of programmers working on different sections of the application.

Alternatively, if you prefer to code a C# program using a text editor, you can use the Notepad (Programs?Accessories?Notepad) application included in every Windows computer. (Be aware, however, that using Notepad does not give you access to the IntelliSense feature, which is available only in Visual Studio 2008.)

1. Using Notepad, create a text file, name it HelloWorld.cs, and save it into a folder on your hard disk, say in C:C#.

2. Populate HelloWorld.cs with the following:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HelloWorld {
 class Program {
  static void Main(string[] args) {
   Console.WriteLine("Hello, world! This is my first C# program!");

3. Use the command-line C# compiler (csc.exe) that ships with Visual Studio 2008 to compile the program. The easiest way to invoke csc.exe is to use the Visual Studio 2008 command prompt, which has all the path references added for you.

4. To launch the Visual Studio 2008 command prompt, select Start?Programs?Microsoft Visual Studio 2008?Visual Studio Tools?Visual Studio 2008 Command Prompt.

5. In the command prompt, change to the directory containing the C# program (C:C# for this example), and type the following command (see Figure 3-4):

C:C#>csc HelloWorld.cs

Figure 3-4

6. Once the program is compiled, you will find the HelloWorld.exe executable in the same directory (C:C#). Type the following to execute the application (see Figure 3-5):


Figure 3-5

7. To return to the command prompt, press Enter.

Оглавление книги

Генерация: 1.053. Запросов К БД/Cache: 3 / 1
Вверх Вниз