2. Installing Visual C# 2008
As of late January 2008, the Express versions of Visual Studio 2008 are available for download [2] at the following address [1]: [http://msdn2.microsoft.com/fr-fr/express/future/default(en-us).aspx]:
![]() |
- [1]: the download address
- [2]: the downloads tab
- [3]: Download C# 2008
Installing C# 2008 will also install the following components:
- the .NET Framework 3.5
- SQL Server Compact 3.5 database management system
- MSDN documentation
To create your first program with C# 2008, follow these steps after launching C#:
![]() |
- [1]: Select File > New Project
- [2]: Select a Console application
- [3]: Name the project—this will be changed below
- [4b]: The project has been created
- [4c]: Program.cs is the default C# program generated in the project.
![]() |
- The first step did not ask where to save the project. If you do nothing, it will be saved to a default location that will likely not suit your needs. Option [5] allows you to save the project to a specific folder.
- You can rename the project in [6] and specify its folder in [7]. To do this, use [8]. In this case, the project will ultimately be located in the folder [C:\temp\08-01-31\MyApplication1].
- By checking [9], you can create a folder for the solution named in [10]. If Solution1 is the name of the solution:
- a folder [C:\temp\08-01-31\Solution1] will be created for the Solution1 solution
- a folder [C:\temp\08-01-31\Solution1\MyApplication1] will be created for the MyApplication1 project. This solution works well for solutions consisting of multiple projects. Each project will have a subfolder within the solution folder.
![]() |
- in [1]: the Windows folder for the MyApplication1 project
- in [2]: its contents
- in [3]: the project in the Visual Studio Project Explorer
Let’s modify the code in the [Program.cs] file [3] as follows:
using System;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
Console.WriteLine("First attempt with C# 2008");
}
}
}
- Line 3: the namespace of the class defined on line 4. Thus, the full name of the class defined on line 4 is ConsoleApplication1.Program.
- Lines 5–7: The static Main method, which is executed when a class is instantiated
- line 6: a screen display
The program can be run as follows:
![]() |
- [Ctrl-F5] to run the project; in [1]
- in [2], the resulting console output.
Execution added files to the project:
![]() |
- in [1], we display all the project files
- in [2]: the [Release] folder contains the project's executable [MyApplication1.exe].
- in [3]: the [Debug] folder, which would also contain a project executable [MyApplication1.exe] if the project had been run in [Debug] mode (F5 key instead of Ctrl-F5). This is not the same executable as the one obtained in [Release] mode. It contains additional information that enables the debugging process to take place.
You can add a new project to the current solution:
![]() |
- [1]: Right-click on the solution (not the project) / Add / New Project
- [2]: Select an application type
- [3]: The default folder is the one containing the existing project folder [MyApplication1]
- 4: Name the new project
The solution now has two projects:
![]() |
- [1]: the new project
- [2]: When the solution is run (F5 or Ctrl-F5), one of the projects is executed. This is the one designated by [2].
A project can have multiple executable classes (containing a Main method). In this case, you must specify which class to run when the project is executed:
![]() |
- [1, 2]: Copy and paste the [Program.cs] file
- [3]: the result of the copy/paste
- [4,5]: Rename both files
![]() |
The P1 class (line 4):
using System;
namespace MyApplication2 {
class P1 {
static void Main(string[] args) {
}
}
}
The P2 class (line 4):
using System;
namespace MyApplication2 {
class P2 {
static void Main(string[] args) {
}
}
}
The [MyApplication2] project now has two classes with a static Main method. You must tell the project which one to run:
![]() |
- in [1]: the properties of the [MyApplication2] project
- in [2]: the choice of which class to run when the project is executed (F5 or Ctrl-F5)
- in [3]: the type of executable produced—here, a Console application will produce an .exe file.
- in 4: the name of the generated executable (without the .exe)
- in [5]: the default namespace. This is the one that will be generated in the code of each new class added to the project. It can then be changed directly in the code, if necessary.










