· Define new terms
· Understand what the IDE is and how it makes programming easier
· Describe the parts of the Visual Studio IDE and their functions
· Explain how to customize the Visual Studio IDE
· Describe how to create a new C# program
Introduction
C# is a part of the Visual Studio .NET platform. Visual Studio includes compliers for a number of different languages besides C#. Visual Studio also includes compilers for Visual Basic and C++. All three of these compilers are part of the .NET platform and share the Common Language Runtime. That means that programs in these languages can all work together very well.
The Visual Studio software includes a system of tools to create a program, test a program, and edit a program. This system is called the Integrated Development Environment or IDE. The IDE is a single tool with one interface, or way of doing things, that a programmer uses to do the whole job of program creation.
In traditional systems a programmer would use one program to create and edit their program, a second program to compile their program and still a third program to debug their program. Each of these programs would be run separately and would have its own set of commands to learn. Having all the tools needed for program development in one integrated program makes working on a program a lot easier.
All of the languages in Visual Studio .NET use the same IDE. This makes it easier for programmers to use or learn multiple languages. With one IDE, programmers do not have to learn different tools for different languages.
The Visual Studio .NET IDE may be started several ways. On most systems, the IDE may be started from the Start menu where it will be listed as Microsoft Visual Studio .NET 7.0
One some systems, a shortcut icon may be on the desktop. Figure 2-x Visual Studio icon shows an example of this icon.

Either of these methods may be used to start the IDE. The initial appearance of the IDE will depend on the settings used on your system.

A project consists of separate components or pieces that are stored as individual files in a solution. A simple project might consist of a form , source code files and a project file. Projects that are more complex might consist of these items plus database scripts or stored procedures, or an HTML document, or a reference to an existing Web service. A project functions like a container that keeps all the pieces together during development and uses them to build a product. The output of a project is usually an executable program (.exe), a dynamic link library (.dll) file or a module..
All projects are contained within a solution and every project contains a unique project file. The project file is a list of the files contained in the project. It is also used to store and track other information about those files. This file is updated every time you save the project.
All the languages that are part of Visual Studio.NET provide a number of pre-defined project templates. A project template creates a new project in your solution and populates it with the files you'll need to develop a project of that type. C# comes with project templates for console applications, Windows form based applications and several other templates.
The files that Visual Studio creates using one of these templates will all be in the same folder. Files in other folders may be added to a project and the project file will store the location of those files.
The easiest way to see how all this works is to actually create a project. In the next two sections, you will step through two versions of what has become the standard first application for all new programmers. It is called “Hello World” and its sole purpose is to show how to create and run a project using the IDE. You will create both a console application and a Windows application so that you can see the similarities and differences for yourself.
The first step is to start the Visual Studio .NET IDE. From the file menu select the New option and then the Project option to create a new project.
The New Project dialogue box will open. Select the C# Console Application and enter a name for the project.

The code window will have the following code automatically to get you started.
namespace ConsoleHelloWorld
{
using System;
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Class1
{
public Class1()
{
//
// TODO: Add Constructor Logic here
//
}
public static int Main(string[] args)
{
//
// TODO: Add code to start application here
//
return 0;
}
}
}
You will learn more details about this code as you go on through the book but some brief introductions are given here.
The lines with the slash marks (// and ///) are comments. Comments are messages to the programmer that explain what the program does. The lines with three slashes are special comments that can be used with compiler options to generate program documentation.
The namespace creates a scope for the project. This will help organize code in complex projects. The keyword using specifies that your program will use the system namespace supplied by the .NET platform. A default class called Class1 is created. All C# programs must be part of a class. Chapter 3 will introduce classes and chapter 4 will explain them in more detail.
The code you will modify for this project is the method called Main. Main is a special function that is required for all application programs. It must be spelled exactly as is show here. The uppercase “M” and lower case “ain” are also required. C# is a case-sensitive language which means that uppercase and lower case letters are not considered the same letter in names. If you create a method called “main” or one called “mAIN” they will not be recognized as the function C# needs to start the program.
The actual code for the Main function will be entered between the set of curly braces ( { } ) that determine the start and finish of the function. You will notice that there is a comment here that tells you that you need to add code to make your program do anything. You will replace those three comment likes with the following statement.
Console.WriteLine("Hello World!");
As you type in this statement, you will notice something interesting. After you type the word Console a drop down box will appear similar to the one in figure 5-x IntelliSense below. The dropdown box shows all of the properties and methods associated with the Console object. As you enter more letters to the statement the selected item will move to the item you are entering. At any time you may press the Tab key to have the IDE finish entering the currently selected list item. The arrow keys may also be used to move the selection up or down through the list. This feature is called IntelliSense and is available for all objects in C#.

The Console object is used to read and write messages to the screen. The WriteLine method writes a line to the console window. The message inside the quotation marks is the message that will be displayed.
There are two write options for the Console object. Write will display the information in the parameter list on the console and leave the cursor at the end of the line. The write method is useful for building a line from several statements or to prompt a user for input. The WriteLine method displays the information in the parameter list and moved the cursor to the next line.
The parameters for either a Write or WriteLine method start with a quoted string. This string may include numbers, starting at zero, that identify a location where the value in an object should be displayed. These numbers are enclosed in curly brackets to and correspond with the objects that follow the quoted string. The first object after the string will be displayed in location zero, the second in location one and so on. These numbers do not have to appear in order and may be duplicated. In other words, {0} could appear more then once and the same value would be displayed in each location.
Once the WriteLine statement has been entered, select the Start option from the Debug menu as shown in figure 2-x Starting a Job.

Your program will be compiled and a console window will be opened. If there are no errors, this console window will look something like figure 2-x Console Hello World.

The Write and WriteLine methods of the Console object have a number of formatting options that can be used to specify how to display the information being printed.
The number of the item in the list of things to be displayed is included in a set of curly braces. For example: {0} This is the simplest form and is used commonly when the format of the informaiont is not important. The more general form for a parameter follows:
{n[,w] [ : FormatString] }
The parts inside square brackets are optional. The square brackets are not actually used. The n represents the number of the argument to be displayed. The w is an integer that represents the number of spaces to use to display the argument. If this value is negative then the information is displayed left justified within the field; if positive, it will be right justified. A number of formatting characters are supported to specify different ways to format numeric output. A number after the format character specifies the number of decimal places to display. Table 2-x, Format Characters, lists these format characters with examples.
|
Format Character |
Description |
Example Code |
Example Output |
|
C |
Locale-specific currency |
{0,15:C} |
$23,12.45 |
|
D |
Integer with optional zero padding |
{0:D5} |
00234 |
|
E |
Scientific with an exponent |
{0:E} {1:E3} |
4.567890E+002 4.468E-002 |
|
F |
Fixed-point - the precision specifier, which may be zero, controls the number of decimal places. |
{0:F} {0:F0} {1:F3} {1:F5} |
3456.79 3457 3456.79 3456.78957 |
|
G |
General - uses the most compact of E or F |
{1:G} |
3456.78957 |
|
N |
Number with embedded commas |
{0:N} {0:N0} {1:N3} |
3,456.79 3457 3,456.79 |
|
X |
Hexadecimal - the precision specifier is used to pad with leading zeros |
{0:X} {0:X4} |
16F 016F |
The formatting characters can be used in lowercase or uppercase.
The Integrated Development Environment (IDE) allows a programmer to create and test programs. Tools that are part of the IDE let the programmer draw objects on a form and specify their attributes or properties. C# program statements are entered using the code editor. Many of the C# statements in a Windows program tell the computer how to react when different things happen to objects on a form.
The IDE lets a programmer create new programs or modify programs that have already been started. Once a program is created the IDE checks to make sure that some required statements have been entered. The IDE will locate and identify all errors. Once that first level of checking has been done, the program can run. The IDE allows the user to run the program and check how well the program functions.
The IDE also lets the programmer save work. The save functions allow the programmer to return to the original work to edit or improve the program.
1. What does IDE stand for?
2. How often should you save your program?
3. Which window is used to enter code for an object?
4. The default name of a text box is displayed in the box when it is drawn on the form. Does changing the name automatically change what is shown in the box on the form?
5. What information is stored in the project file?
6. What is the difference between Save Project and Save Project As?
7. What is the default extension of a form file? Of a project file?
8. Controls are selected from what section of the IDE?
9. Commonly used tools are selected from icons on what part of the IDE?
10. How do you customize the IDE startup so that the last project you were working on is opened automatically?
Application Code Code is the set of instructions a programmer gives to a computer to tell it how to do the work.
Control A control is a type of object that is drawn on the form of a Visual Studio program.
Compile Compile means to take the programmer’s information and turn it into a set of instructions that can be understood by the computer.
Debug Debugging a program is the job of running a program to find out if it works and fixing any problems.
IDE The Integrated Development Environment is a set of tools that work together to make program development and testing easy.
Project A project is a Visual Studio program that is made up of one or more files. A project file keeps track of the forms and other files that make up the project.
Property A property is a characteristic of an object. (i.e., height, width, name.) Properties describe what an object looks like and how it is used.
User Interface The part of a computer program that gives information to a user and receives information from the user.