Read Microsoft Visual C# 2005 Express Edition: Build a Program Now! Online
Authors: Patrice Pelland
Tags: #General, #Computers, #C♯ (Computer program language), #Programming Languages, #C#, #Microsoft .NET Framework, #Computer Books: Languages, #Computer Graphics, #Application software, #C# (Computer program language), #Programming, #Microsoft Visual C# .NET, #Microsoft Visual C♯ .NET, #Electronic books, #Game Programming & Design, #Computing: Professional & Programming, #C (Computer program language), #Computers - Languages, #Programming Languages - C#, #Programming & scripting languages: general
Windows XP SP2 comes with
a graphical interface for a Windows application. For example, a Windows service is an appli
roughly four dozen Windows
cation that runs on Windows in the background—it doesn’t have a user interface, doesn’t
services. For example, a Windows
service validates your user name
produce any visual output, starts when Windows starts, and doesn’t even require
and password at start up.
a user to be logged in to start executing.
In some other cases, you don’t want users to interact with a graphical interface you’ve created. For instance, you could write an application that monitors the available physical memory on a computer then displays that information once it reaches a certain level. The information is displayed in a user interface but does not require any input from the user. Figure 3-1 shows the result of the famous Hello World! application as a console application.
Figure 3-1
Console application
This type of application is called a console application because everything is displayed in a system console window. You may have heard these types of windows referred to by many different names: a DOS window, a command prompt window, or simply the command window. The most common output in a console application is simple text.
26
Microsoft Visual C# 2005 Express Edition: Build a Program Now!
CSX_chapter3.indd 26
CSX_chapter3.indd 26
10/24/05 3:03:16 PM
10/24/05 3:03:16 PM
Console applications can be as feature rich and as complex as Windows applications. The only difference is that they don’t have a graphical interface. Let’s look at one possible use for console applications.
In corporate data centers, many applications execute all day and night, producing a large amount of data. It would be time-consuming and problematic to rely on people to
Simple Text and
verify the data. So data centers are usually highly automated to facilitate this job. Console
ASCII Characters
applications produce, manipulate, and verify the data in scripts or batch files. Console
Simple text (also called
applications can be written in many different programming languages (C, C++, C#, Visual
ASCII characters) is the usual
Basic, and so on) and scripting languages (Perl, Python, or JScript®).
output of a console application,
In contrast to a console application, a Windows
but some console applications
use ASCII graphic characters.
application has a graphical interface, as shown in
(ASCII stands for American
Figure 3-2. (It is also called a Windows Forms
Standard Code for Information
application in .NET).
Interchange.) An ASCII code is
These applications are usually installed and accessi
the numerical representation
ble in the Windows Start menu, and by default they
of a character (such as “0”or
share some common characteristics, such as a Close
“#”) or an action of some sort.
(Pressing Enter in a word pro-
button, a Maximize button, and a Minimize button.
cessor to move a line of text is
an action represented by an
ASCII character, for instance.)
Close Button
Maximize Button
Minimize Button
The ASCII graphic character set,
Figure 3-2
also called extended ASCII char-
Windows application
acters, includes vertical lines,
vertical double lines, corners,
and much more. ASCII charac-
ters are sometimes used to cre-
Getting Started
ate boxes around text in console
applications.
To get started writing the code for the first version of the application, you’ll need to start Microsoft Visual C# 2005 Express Edition. To do this follow these three easy steps: click Start, choose All Programs, then select Microsoft Visual C# 2005 Express Edition.
Please note that console appli-
cations are still executed in
Windows, but in a console context.
Chapter 3: Creating Your First Application
27
CSX_chapter3.indd 27
CSX_chapter3.indd 27
10/24/05 3:03:16 PM
10/24/05 3:03:16 PM
The first time you start Microsoft Visual C# 2005 Express Edition, it will take some time to load since the IDE is being configured. You should see a screen similar to Figure 3-3. Before we go futher, let’s pause and
admire the IDE in all its glory. With this version of Visual C#, the IDE got a nice new
Figure 3-3
Environment configuration for first
makeover. Look at Figure 3-4 and feel the
time use of Microsoft Visual C# 2005
excitement.
Express Edition
If you’re not feeling the excitement yet,
you soon will. The development environment has been designed to make a lot more information available up front and to get you more productive faster. From this screen, everything you need to build an application is available in a couple of clicks. From the IDE you Menu Bar
Main Toolbar
Toolbox
Solution Explorer
Recent Projects
MSDN Visual C# RSS
Feed
Getting Started
Visual C#
Express Headlines
Status Bar
Figure 3-4
The IDE in all its glory
28
Microsoft Visual C# 2005 Express Edition: Build a Program Now!
CSX_chapter3.indd 28
CSX_chapter3.indd 28
10/24/05 3:03:17 PM
10/24/05 3:03:17 PM
type in your code, compile your code, launch the application, find your mistakes and fix them, get help on the syntax, and many other things. Furthermore, the Visual C# 2005 IDE is designed to help you by generating a lot of code for you so that you have less to type in. If you didn’t have the IDE and you wanted to write a Windows Forms application, you would
normally have to write a lot more code and it would be more prone to errors. With the new
I will show you how and where
IDE, most of the actions you’ll perform will automatically generate a lot of code behind the
to look for this generated code in
Chapter 5.
scenes.
As you spend more time with the program, you’ll find that there are many different ways to perform the same actions. For instance, to complete a specific action you can use a series of menu choices, or use a keystroke shortcut, or click an
icon
on a
toolbar
, click on a
hyperlink
in a page, or you can right-click and choose an option from a
context-sensitive
menu
. Before diving into our first application and before you write some code, we’ll go
through each big component of the IDE.
Even when the Start Page disap-
The first page you see is a really useful one: the Start Page. Let’s get into what
pears, you can always get it back
information you see on that page.
by going to the View menu and
selecting Start Page.
■
Recent Projects
Here you’ll get the list of projects or solutions that were recently
The first and only rule of this book
is to not be afraid to experiment.
opened. You can also create a new project or open an existing project that is not in
Click, look, read, and try when-
the list.
ever possible. This is really the
best way to learn. I’ll show you
■
Getting Started
I call this useful section Help Central because if you need quick help,
some important material, tips, and
tricks throughout this book, but