###E###
Preface
Welcome to the Visual C#® 2010 programming language and the world of Microsoft®
Windows® and Internet programming with Microsoft’s .NET platform!
This book focuses on software engineering best practices. At the heart of the book is
the Deitel signature “live-code approach.” Concepts are presented in the context of working
programs, rather than in code snippets. Each code example is accompanied by sample exe-
cutions. All the source code is available at www.deitel.com/books/vcsharp2010htp/ and
at the book’s Companion Website at www.pearsonhighered.com/deitel/.
As you read the book, if you have questions, send an e-mail to deitel@deitel.com;
we’ll respond promptly. For updates on this book and its supporting Visual C# software,
visit www.deitel.com/books/vcsharp2010htp/, follow us on Twitter (@deitel) and
Facebook (www.deitel.com/deitelfan), and subscribe to the Deitel® Buzz Online news-
letter (www.deitel.com/newsletter/subscribe.html).
New and Updated Features
Here are the updates we’ve made for Visual C# ® 2010 How to Program, 4/e:
•
Printed book contains core content; advanced chapters are online. The printed book
contains sufficient core content for most introductory Visual C# course sequences.
Several online chapters are included for more advanced courses and for profession-
als. These are available in searchable PDF format on the book’s password-protected
Companion Website—see the access card in the front of this book.
The book’s Companion Website includes extensive VideoNotes in which co-
author Paul Deitel explains in detail most of the programs in the core chapters.
• Making a Difference exercises set. We encourage you to use computers and the
Internet to research and solve significant social problems. These new exercises are
meant to increase awareness and discussion of important issues the world is fac-
ing. We hope you’ll approach them with your own values, politics and beliefs.
•
• Up-to-date with Visual C# 2010, C# 4, the Visual Studio 2010 IDE and .NET
4. The C# language has been standardized internationally by ECMA and ISO.
The latest version of that language is referred to as C# 4. Microsoft’s implemen-
tation of this standard is referred to as Visual C# 2010.
• New language features. We cover new C# features, such as optional parameters,
named parameters, covariance and contravariance.
• Databases. We use Microsoft’s free SQL Server Express (which installs with the
free Visual C# Express) to teach the fundamentals of database programming.
Chapters 18, 19, 27 and 28 use database and LINQ fundamentals in the context
of an address-book desktop application, a web-based guestbook, a bookstore and
an airline reservation system.
Download at www.pin5i.com
xviii
Preface
•
ASP.NET 4. Microsoft’s .NET server-side technology, ASP.NET, enables you to
create robust, scalable web-based applications. In Chapter 19, you’ll build several
applications, including a web-based guestbook application that uses ASP.NET,
LINQ and a LinqDataSource to store data in a database and display data in a web
page. The chapter also discusses the ASP.NET Development Server for testing
your web applications on your local computer.
• We removed generic methods from Chapter 9 to make the code easier to under-
•
stand.
The code will run onWi ndows 7, Windows Vista and Windows XP. We’ll post
any issues on www.deitel.com/books/vcsharp2010htp/.
• We introduce exception handling much earlier (Chapter 8) and integrated it in
subsequent chapters in which it had not been used previously. We also now
throw exceptions for invalid data received in the set accessors of properties.
• New design. The book has a new interior design that graphically organizes, clari-
fies and highlights the information, and enhances the book’s pedagogy. We used
italics extensively to emphasize important words, phrases and points in the text.
• We titled the programming exercises to help instructors tailor assignments.
Other features of Visual C# 2010 How to Program, 4/e include:
• We’ve provide instructors with solutions to the vast majority of the exercises. There
are a few large exercises marked “Project” for which solutions are not provided.
• We use LINQ (Language Integrated Query) to query files, databases, XML and
collections. The introductory LINQ chapter, Chapter 9, in the core printed book
is intentionally brief to encourage instructors to cover this important technology
early. The online chapters continue the discussion of LINQ.
Local type inference. When you initialize a local variable in its declaration, you
can now omit the variable’s type—the compiler infers it from the initializer value.
• Object initializers. For new objects, you can use object initializer syntax (similar
to array initializer syntax) to assign values to the new object’s public properties
and public instance variables.
•
• We emphasize the IDE’s IntelliSense feature that helps you write code faster and
with fewer errors.
Our Text + Digital Approach to Content
We surveyed hundreds of instructors teaching Visual C# courses and learned that most
want a book with content focused on their introductory courses. With that in mind, we
moved various intermediate and advanced chapters to the web. Having this content in dig-
ital format makes it easily searchable, and gives us the ability to fix errata and add new con-
tent as appropriate. The book’s Companion Website at
www.pearsonhighered.com/deitel/
(see the access card at the front of the book) contains the following chapters in searchable
PDF format:
Download at www.pin5i.com
Dependency Charts
xix
• WPF (Windows Presentation Foundation) GUI, graphics and multimedia. We ex-
tend the core book’s GUI coverage in Chapters 24–25 with an introduction to
Windows Presentation Foundation (WPF)—Microsoft’s new framework that in-
tegrates GUI, graphics and multimedia capabilities. We implement a painting ap-
plication, a text editor, a color chooser, a book-cover viewer, a television video
player, various animations, and speech synthesis and recognition applications.
ASP.NET 4 and ASP.NET AJAX. Chapter 27 extends Chapter 19’s ASP.NET
discussion with a case study on building a password-protected, web-based book-
store application. We also introduce ASP.NET AJAX controls and use them to
add AJAX functionality to web applications to improve their responsiveness.
•
•
• WCF (Windows Communication Foundation) Web Services. Web services en-
able you to package application functionality in a manner that turns the web into
a library of reusable services. In Chapter 28, we include case studies on building
an airline reservation web service, a blackjack web service and a math question
generator web service that’s called by a math tutor application.
Silverlight. Chapter 29 introduces Silverlight, which enables you to create visu-
ally stunning, multimedia-intensive user interfaces for web applications. The
chapter presents powerful multimedia applications, including a weather viewer,
Flickr photo viewer, deep zoom book-cover collage and video viewer.
Visual C# XML capabilities. Use of the Extensible Markup Language (XML) is ex-
ploding in the software-development industry and in e-business, and is pervasive
throughout the .NET platform. In Chapter 26, we use show how to programmat-
ically manipulate the elements of an XML document using LINQ to XML.
•
• Optional Case Study: Using the UML to Develop an Object-Oriented Design and
C# Implementation of an ATM. The UML™ (Unified Modeling Language™) is
the preferred graphical modeling language for designing object-oriented systems.
This edition includes an optional online case study on object-oriented design using
the UML (Chapters 30–31). We design and implement the software for a simple
automated teller machine (ATM). We analyze a typical requirements document
that specifies the system to be built. We determine the classes needed to implement
that system, the attributes the classes need to have, the behaviors the classes need to
exhibit and specify how the classes must interact with one another to meet the sys-
tem requirements. From the design we produce a working Visual C# implementa-
tion. We’ve presented this case study to professional audiences in C#, Java, Visual
Basic and C++. After seeing the case-study presentation, students report having a
“light-bulb moment”—the case study “ties it all together” for them and helps them
understand how objects in a larger system communicate with one another.
Index. The online index includes the content from the printed book and the on-
line content. The printed book index covers only the printed material.
•
Dependency Charts
The charts in Figs. 1–2 show the dependencies among the chapters to help instructors plan
their syllabi. The printed book focuses on introductory course sequences (Fig. 1). The online
chapters include intermediate and advanced content for more advanced courses (Fig. 2).
Download at www.pin5i.com
xx
Preface
Dependency Chart
for Print Chapters1
Strings, Files and
Data Structures
16 Strings
and Characters
Introduction to Visual C#
Fundamentals and
Object-Oriented Programming
1 Introduction to Computers, the
Internet and Visual C#
2 Dive Into® Visual C# 2010 Express
3 Introduction to C# Applications
4 Introduction to Classes,
Objects, Methods and strings
5 Control Statements: Part 1
6 Control Statements: Part 2
7 Methods: A Deeper Look
8 Arrays2
Object-Oriented Programming:
A Deeper Look
9 Introduction to LINQ and
the List Collection
10 Classes and Objects:
A Deeper Look
11 OOP: Inheritance
17 Files and Streams3
12 OOP: Polymorphism, Interfaces
20 Searching and Sorting
21 Data Structures4
22 Generics
23 Collections
13 Exception Handling:
A Deeper look
Graphical User Interfaces
14 GUI with Windows
Forms: Part 1
15 GUI with Windows
Forms: Part 2
Database and Web
App Development
18 Databases
and LINQ5
19 Web App Development
with ASP.NET6
1. See Fig. 2 for the online chapters.
2. Chapter 8 introduces exception handling.
3. Requires Sections 14.1–14.5.
4. Requires Sections 14.1–14.5 and 15.6.
5. Requires Sections 14.1–14.6 and 15.8.
6. Requires general GUI and event-handling knowledge (Sections 14.1–14.3).
Fig. 1 | Chapter dependency chart for the chapters in the printed book.
Download at www.pin5i.com
Teaching Approach
xxi
Dependency Chart for
Online Chapters
LINQ, Databases and Web
App Development
9 Introduction to LINQ and
the List Collection
18 Databases and
LINQ to SQL
19 Web App Development
with ASP.NET
Object-Oriented Programming
10 Classes and Objects:
A Deeper Look
11 OOP: Inheritance
12 OOP: Polymorphism, Interfaces
WPF GUI and Graphics
24 GUI with Windows
Presentation Foundation
25 WPF Graphics and Multimedia
Web App Development
26 XML and LINQ to XML1
27 Web App Development
with ASP.NET: A Deeper Look
28 WCF Web Services
29 Silverlight and
Rich Internet Applications
Object-Oriented Design
30 ATM Case Study, Part 1:
Object-Oriented Design
with the UML
31 ATM Case Study, Part 2:
Implementing an
Object-Oriented Design
1. Chapter 26 depends on the introduction to XML in Chapter 24.
Fig. 2 | Chapter dependency chart for the online chapters.
Teaching Approach
Visual C# 2010 How to Program, 4/e contains a rich collection of examples. We concen-
trate on building good software and stress program clarity.
Live-Code Approach. The book is loaded with “live-code” examples. Most new concepts
are presented in the context of complete working Visual C# applications, followed by one
or more executions showing program inputs and outputs. In the few cases where we use
snippets, we tested them in complete working programs then copied the code from the
program and pasted it into the book.
Syntax Shading. For readability, we syntax shade the code, similar to the way most inte-
grated-development environments and code editors syntax color the code. Our syntax-
shading conventions are:
comments appear like this
keywords appear like this
constants and literal values appear like this
all other code appears in black
Code Highlighting. We place gray rectangles around each program’s key code.
Download at www.pin5i.com
xxii
Preface
Using Fonts for Emphasis. We place the key terms and the index’s page reference for each
defining occurrence in bold text for easy reference. We emphasize on-screen components
in the bold Helvetica font (for example, the File menu) and Visual C# program text in the
Lucida font (for example, int count = 5).
Objectives. The opening quotes are followed by a list of chapter objectives.
Illustrations/Figures. Abundant tables, line drawings, UML diagrams, programs and pro-
gram outputs are included.
Programming Tips. We include programming tips to help you focus on important as-
pects of program development. These tips and practices represent the best we’ve gleaned
from a combined seven decades of programming and teaching experience.
Good Programming Practice
The Good Programming Practices call attention to techniques that will help you pro-
duce programs that are clearer, more understandable and more maintainable.
Common Programming Error
Pointing out these Common Programming Errors reduces the likelihood that you’ll
make them.
Error-Prevention Tip
These tips contain suggestions for exposing and removing bugs from your programs; many
of the tips describe aspects of Visual C# that prevent bugs from getting into programs.
Performance Tip
These tips highlight opportunities for making your programs run faster or minimizing the
amount of memory that they occupy.
Portability Tip
The Portability Tips help you write code that will run on a variety of platforms.
Software Engineering Observation
The Software Engineering Observations highlight architectural and design issues that
affect the construction of software systems, especially large-scale systems.
Look-and-Feel Observation
These observations help you design attractive, user-friendly graphical user interfaces that
conform to industry norms.
Summary Bullets. We present a section-by-section, bullet-list summary of each chapter.
Terminology. We include an alphabetized list of the important terms defined in each chap-
ter.
Self-Review Exercises and Answers. Extensive self-review exercises and answers are includ-
ed for self-study.
Download at www.pin5i.com
Student Resources and Software
xxiii
Exercises. Each chapter concludes with additional exercises including:
simple recall of important terminology and concepts
•
• What’s wrong with this code?
• What does this code do?
•
•
• major projects.
writing individual statements and small portions of methods and classes
writing complete methods, classes and programs
Please do not write to us requesting access to the Pearson Instructor’s Resource Center
which contains the book’s instructor supplements, including the exercise solutions. Ac-
cess is limited strictly to college instructors teaching from the book. Instructors may ob-
tain access only through their Pearson representatives. Solutions are not provided for
“project” exercises. Check out our Programming Projects Resource Center for lots of ad-
ditional exercise and project possibilities (www.deitel.com/ProgrammingProjects/).
Index. We’ve included an extensive index for reference. Defining occurrences of key terms
are highlighted with a bold page number.
Student Resources and Software
This book includes the Microsoft® Visual Studio® 2010 Express Editions DVD, which
contains the Visual C#® 2010 Express Edition (and other Microsoft development tools).
These tools are also downloadable from
www.microsoft.com/express/Windows
We wrote Visual C# 2010 How to Program using Visual C#® Express Edition. You can
learn more about Visual C#® at msdn.microsoft.com/vcsharp.
Deitel Online Resource Centers
Our website www.deitel.com provides Resource Centers on various topics of interest to
our readers (www.deitel.com/ResourceCenters.html). We’ve found many exceptional
resources online, including tutorials, documentation, software downloads, articles, blogs,
podcasts, videos, code samples, books, e-books and more—most are free. Some of the Re-
source Centers you might find helpful while studying this book are Visual C#, ASP.NET,
ASP.NET AJAX, LINQ, .NET, Silverlight, SQL Server, Web Services, Windows Com-
munication Foundation, Windows Presentation Foundation, Windows 7, UML, Code
Search Engines and Code Sites, Game Programming and Programming Projects.
Instructor Supplements
The following supplements are available to qualified instructors only through Pearson
Education’s Instructor Resource Center (www.pearsonhighered.com/irc):
•
•
•
Solutions Manual with solutions to most of the end-of-chapter exercises.
Test Item File of multiple-choice questions (approximately two per book section)
PowerPoint® slides containing all the code and figures in the text, plus bulleted
items that summarize key points.
Download at www.pin5i.com