Getting Started with the
Visual Studio IDE
The Visual Studio integrated development environment (IDE) plays a central role in
Visual C# development. In this lesson you explore the IDE. You learn how to configure it
for Visual C# development, and you learn about some of the more useful of the IDE’s win-
dows and what they do. When you finish this lesson, you’ll know how to create a new proj-
ect. It may not do much, but it will run and will prepare you for the lessons that follow.
Visual Studio is a development environment that you can use with several pro-
gramming languages including Visual C#, Visual Basic, Visual C++, and F#.
C# is a high-level programming language that can read inputs, calculate results,
display outputs to the user, and perform other operations typical of high-level
programming languages.
Visual C# is the combination of C# used in the Visual Studio development envi-
ronment. You can use a text editor to write C# programs without Visual Studio,
but its a lot of work and is not the focus of this book.
Visual C# and C# go together like politicians and bickering: if you mention one,
most people assume you’re also talking about the other. Most people simply say
C#, so this book does, too, unless there’s a reason to distinguish between C# and
Visual C#.
The .NET Framework also plays an important role in C# programs. It includes
classes that make performing certain tasks easier, runtime tools that make it
possible to execute C# programs, and other plumbing necessary to build and
run C# programs.
Normally you don’t need to worry about whether a feature is provided by Visual
Studio, the C# language, or the .NET Framework. They all go together in this
book, so for the purposes of this book at least you can ignore the difference.
1
596906c01.indd 3 4/7/10 12:31:22 PM
4
LESSON 1 GettinG Started with the ViSual Studio ide
INSTALLING C#
Before you can use C# to write the next blockbuster first-person Xbox game, you need to install it.
So if you haven’t done so already, install C#.
You can install the Express Edition at
www.microsoft.com/express/Windows. If you think you
need some other version (for example, you’re working on a big project and you need test manage-
ment, source code control, and other team programming tools), go to
msdn.microsoft.com/
vcsharp
and install the version that’s right for you.
It’s a big installation, so it could take a while.
TALKIN’ ’BOUT MY GENERATION
Developers talk about different generations of programming languages ranging
from the very primitive to quite advanced. In a nutshell, the different generations
of languages are:
1GL
Machine language. This is a series of 0s and 1s that the machine can
understand directly.
2GL
Assembly language. This is a translation of machine language into
terse mnemonics that can be easily translated into machine language. It pro-
vides no structure.
3GL
A higher-level language such as FORTAN or BASIC. These provide
additional structure (such as looping and subroutines) that makes building
complex programs easier.
4GL
An even higher-level language or development environment that helps
build programs, typically in a specific problem domain.
5GL
A language where you specify goals and constraints and the language
figures out how to satisfy them. For example, the database Structured Query
Language (SQL) allows you to use statements like
SELECT FirstName FROM
Employees
. You don’t need to tell the database how to get the names; it fig-
ures that out for you.
Visual Studio provides code snippets that let you copy standard chunks of code into
your program, IntelliSense that helps you select and use functions and other pieces
of code, refactoring tools that help you rearrange and restructure your code, and
more. That makes Visual C# a 4GL (or perhaps a 3.5GL depending on how high
your standards are).
596906c01.indd 4 4/7/10 12:31:23 PM
Building Your First Program
5
CONFIGURING THE IDE
When you first run Visual Studio, it asks how you want to configure the IDE. You can pick settings
for general development, Visual Basic, Visual C#, and so forth. Because you’re going to be focusing
on C# development, select that option.
These settings determine such things as what keystrokes activate certain devel-
opment features. You can certainly write C# programs with the Visual C++
settings but we may as well be on the same page, so when I say, “Press F5,”
the IDE starts your program instead of displaying a code window or whatever
Visual C++ thinks F5 means.
If you ever want to switch to different set-
tings (for example, if you got carried away
during installation and selected the general
settings and now want the C# settings),
you can always change them later.
To change the settings later, open
the Tools menu and select Import and
Export Settings to display the Import
and Export Settings Wizard. You can use
this tool to save your current settings,
reload previously saved settings, or reset
settings to default values.
To reset settings, select the Reset All
Settings option on the wizard’s first page
and click Next.
On the next page, indicate whether you
want to save your current settings. When
you’ve made your choice, click Next to
display the page shown in Figure 1-1.
Select the Visual C# Development
Settings choice and click Finish. (Then sit back and wait. Or better still, go get a coffee because
this could take a while. Visual Studio has a lot of settings to reset, and it could take several minutes
depending on how fast and busy your computer is.)
BUILDING YOUR FIRST PROGRAM
Now that you’ve installed C#, you’re ready to get started. Launch Visual Studio by double-clicking
its desktop icon or by selecting it from the system’s Start menu.
FIGURE 11
596906c01.indd 5 4/7/10 12:31:23 PM
6
LESSON 1 GettinG Started with the ViSual Studio ide
To create a new project, press [Ctrl]+[Shift]+N to display the New Project dialog box shown in
Figure 1-2. Alternatively, you can open the File menu, expand the New submenu, and select Project.
FIGURE 12
Expand the Visual C# project type folder on the left and select the template for the type of project
that you want to build on the right. For most of this book, that will be a Visual C# Windows Forms
Application.
Below the list of project types, you need to enter several pieces of information.
Name
This is the application’s name. Visual Studio creates a folder with this name to hold
the program’s files. It also sets some key values in the project to this name.
Location
This is where you want Visual Studio to put the project’s folder.
Solution Name
If the Create Directory for Solution box is checked (which it is by default),
Visual Studio creates a folder with this name at the location you entered. It then places the
application’s folder inside the solution’s folder.
So if the Create Directory for Solution box is checked, you get a filesystem layout that looks
like this:
SolutionFolder
SolutionFiles
596906c01.indd 6 4/7/10 12:31:23 PM
Building Your First Program
7
ApplicationFolder
ApplicationFiles
If the Create Directory for Solution box is not checked, you get a filesystem layout that looks like this:
ApplicationFolder
ApplicationFiles
An application contains a single program. A solution can contain several appli-
cations. A solution is useful when you want to build applications that go closely
together. Its particularly useful if you want to build a library of routines plus an
executable program to test the library.
The applications you build in this book are single programs so they don’t really need to be inside a
separate solution folder. Most of the time, I uncheck the Create Directory for Solution box to keep
my filesystem simpler.
By default, Visual Studio places new projects in your Projects folder at
some obscure location such as C:UsersMyUserNameDocumentsVisual
Studio 2010Projects. Later it can be hard finding these projects in Windows
Explorer (for example, to make a copy).
To make finding projects easier, set the location to something more intuitive
such as the desktop or a folder on the desktop. The next time you create a new
project, Visual Studio will initialize the location textbox to this same location,
so from now on it’ll be easy to find your projects.
If you open the New Project dialog box while you have another project open, you’ll see an additional
dropdown that lists the choices Create New Solution and Add to Solution. The first choice closes the
current solution and creates a new one. The second choice adds the new application to the solution
you currently have open. Normally you’ll want to create a new solution.
After you display the New Project dialog box and enter a Name, Location, and Solution Name,
click OK. The result should look like Figure 1-3.
If you have previously edited a project, you can quickly reload it from the File
menu’s Recent Projects submenu. You can also load a solution into the IDE by
double-clicking the solution’s
.sln file.
596906c01.indd 7 4/7/10 12:31:24 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.170.134