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 executions. 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 ; 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 newsletter (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 professionals. 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 coauthor 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 facing. 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 implementation 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.

  • 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 understand.

  • The code will run on Windows 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, clarifies 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 digital format makes it easily searchable, and gives us the ability to fix errata and add new content 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:

  • WPF (Windows Presentation Foundation) GUI, graphics and multimedia. We extend the core book’s GUI coverage in Chapters 24–25 with an introduction to Windows Presentation Foundation (WPF)—Microsoft’s new framework that integrates GUI, graphics and multimedia capabilities. We implement a painting application, 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 bookstore 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 enable 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 visually 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 exploding in the software-development industry and in e-business, and is pervasive throughout the .NET platform. In Chapter 26, we use show how to programmatically 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 system requirements. From the design we produce a working Visual C# implementation. 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 online 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).

Dependency Chart for Print Chapters1

Chapter dependency chart for the chapters in the printed book.
  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).

Figure 1. Chapter dependency chart for the chapters in the printed book.

Dependency Chart for Online Chapters

Chapter dependency chart for the online chapters.

1. Chapter 26 depends on the introduction to XML in Chapter 24.

Figure 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 concentrate 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 integrated-development environments and code editors syntax color the code. Our syntaxshading 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.

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 program outputs are included.

Programming Tips. We include programming tips to help you focus on important aspects 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

Good Programming Practice

The Good Programming Practices call attention to techniques that will help you produce programs that are clearer, more understandable and more maintainable.

Common Programming Error

Common Programming Error

Pointing out these Common Programming Errors reduces the likelihood that you’ll make them.

Error-Prevention Tip

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

Performance Tip

These tips highlight opportunities for making your programs run faster or minimizing the amount of memory that they occupy.

Portability Tip

Portability Tip

The Portability Tips help you write code that will run on a variety of platforms.

Software Engineering Observation

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

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 chapter.

Self-Review Exercises and Answers. Extensive self-review exercises and answers are included for self-study.

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?

  • writing individual statements and small portions of methods and classes

  • writing complete methods, classes and programs

  • major projects.

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. Access is limited strictly to college instructors teaching from the book. Instructors may obtain access only through their Pearson representatives. Solutions are not provided for “project” exercises. Check out our Programming Projects Resource Center for lots of additional 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 Resource 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 Communication 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.

If you’re not a registered faculty member, contact your Pearson representative or visit www.pearsonhighered.com/educator/replocator/.

CourseSmart Web Books

Today’s students and instructors have increasing demands on their time and money. Pearson has responded to that need by offering digital texts and course materials online through CourseSmart. CourseSmart allows faculty to review course materials online, saving time and costs. It is also environmentally sound and offers students a high-quality digital version of the text for as much as 50% off the cost of a print copy of the text. Students receive the same content offered in the print textbook enhanced by search, note-taking, and printing tools. For more information, visit www.coursesmart.com.

Microsoft Developer Network Academic Alliance (MSDNAA) and Microsoft DreamSpark

Microsoft Developer Network Academic Alliance (MSDNAA)—Free Microsoft Software for Academic and Research Purposes

The MSDNAA provides free software for academic and research purposes. For software direct to faculty, visit www.microsoft.com/faculty. For software for your department, visit www.msdnaa.com.

Microsoft DreamSpark—Professional Developer and Designer Tools for Students

Microsoft provides many of its developer tools to students for free via a program called DreamSpark (www.dreamspark.com). See the website for details on verifying your student status so you take advantage of this program.

Acknowledgments

We’d like to thank Abbey Deitel and Barbara Deitel of Deitel & Associates, Inc., who devoted long hours of research and writing to this book.

We are fortunate to have worked on this project with the dedicated team of publishing professionals at Pearson. We appreciate the guidance, savvy and energy of Michael Hirsch, Editor-in-Chief of Computer Science. Carole Snyder recruited the book’s reviewers and managed the review process. Kristine Carney designed the book’s cover. Bob Engelhardt and Jeffrey Holcomb managed the book’s production.

Reviewers

We wish to acknowledge the efforts of our fourth edition reviewers. Adhering to a tight schedule, they scrutinized the text and the programs and provided countless suggestions for improving the presentation:

  • Octavio Hernandez, Microsoft C# MVP, Advanced Bionics

  • José Antonio González Seco, Parliament of Andalusia, Spain

  • Zijiang Yang, Western Michigan University

Previous Edition Reviewers

Huanhui Hu (Microsoft Corporation), Narges Kasiri (Oklahoma State University), Charles Liu (University of Texas at San Antonio), Dr. Hamid R. Nemati (The University of North Carolina at Greensboro), Jeffrey P. Scott (Blackhawk Technical College), José Antonio González Seco (Parliament of Andalusia, Spain), Douglas B. Bock (MCSD.NET, Southern Illinois University Edwardsville), Dan Crevier (Microsoft), Amit K. Ghosh (University of Texas at El Paso), Marcelo Guerra Hahn (Microsoft), Kim Hamilton (Software Design Engineer at Microsoft and co-author of Learning UML 2.0), James Edward Keysor (Florida Institute of Technology), Helena Kotas (Microsoft), Chris Lovett (Software Architect at Microsoft), Bashar Lulu (INETA Country Leader, Arabian Gulf), John McIlhinney (Spatial Intelligence; Microsoft MVP 2008 Visual Developer, Visual Basic), Ged Mead (Microsoft Visual Basic MVP, DevCity.net), Anand Mukundan (Architect, Polaris Software Lab Ltd.), Timothy Ng (Microsoft), Akira Onishi (Microsoft), Joe Stagner (Senior Program Manager, Developer Tools & Platforms), Erick Thompson (Microsoft) and Jesús Ubaldo Quevedo-Torrero (University of Wisconsin–Parkside, Department of Computer Science)

Well, there you have it! Visual C# 2010 is a powerful programming language that will help you write programs quickly and effectively. It scales nicely into the realm of enterprise-systems development to help organizations build their business-critical and missioncritical information systems. As you read the book, we’d appreciate your comments, criticisms, corrections and suggestions for improvement. Please address all correspondence to:

We’ll respond promptly. We hope you enjoy working with Visual C# 2010 How to Program, 4/e as much as we enjoyed writing it!

Paul Deitel and Harvey Deitel

August 2010 Maynard, Massachusetts

About the Authors

Paul J. Deitel, CEO and Chief Technical Officer of Deitel & Associates, Inc., is a graduate of MIT, where he studied Information Technology. Through Deitel & Associates, Inc., he has delivered hundreds of C#, Visual Basic, Java, C++, C and Internet programming courses to industry clients, including Cisco, IBM, Sun Microsystems, Dell, Lucent Technologies, Fidelity, NASA at the Kennedy Space Center, the National Severe Storm Laboratory, White Sands Missile Range, Rogue Wave Software, Boeing, SunGard Higher Education, Stratus, Cambridge Technology Partners, One Wave, Hyperion Software, Adra Systems, Entergy, CableData Systems, Nortel Networks, Puma, iRobot, Invensys and many more. He and his co-author, Dr. Harvey M. Deitel, are the world’s best-selling programming-language textbook authors.

Dr. Harvey M. Deitel, Chairman and Chief Strategy Officer of Deitel & Associates, Inc., has 49 years of experience in the computer field. Dr. Deitel earned B.S. and M.S. degrees from MIT and a Ph.D. from Boston University. He has extensive college teaching experience, including earning tenure and serving as the Chairman of the Computer Science Department at Boston College before founding Deitel & Associates, Inc., with his son, Paul J. Deitel. He and Paul are the co-authors of dozens of books and LiveLessons multimedia packages and they are writing many more. With translations published in Japanese, German, Russian, Chinese, Spanish, Korean, French, Polish, Italian, Portuguese, Greek, Urdu and Turkish, the Deitels’ texts have earned international recognition. Dr. Deitel has delivered hundreds of professional programming seminars to major corporations, academic institutions, government organizations and the military.

About Deitel & Associates, Inc.

Deitel & Associates, Inc., is an internationally recognized corporate training and authoring organization specializing in computer programming languages, Internet and web software technology, object-technology education and Android™ and iPhone® app development. The company provides instructor-led courses delivered at client sites worldwide on major programming languages and platforms, such as C++, Visual C++®, C, Java™, Visual C#®, Visual Basic®, XML®, Python®, object technology, Internet and web programming, Android and iPhone app development, and a growing list of additional programming and software-development courses. The founders of Deitel & Associates, Inc., are Paul J. Deitel and Dr. Harvey M. Deitel. The company’s clients include many of the world’s largest companies, government agencies, branches of the military, and academic institutions. Through its 34-year publishing partnership with Prentice Hall/Pearson, Deitel & Associates, Inc., publishes leading-edge programming textbooks, professional books, interactive multimedia Cyber Classrooms, and LiveLessons DVD-based and web-based video courses. Deitel & Associates, Inc., and the authors can be reached via e-mail at:

To learn more about Deitel & Associates, Inc., its publications and its Dive Into® Series Corporate Training curriculum delivered at client locations worldwide, visit:

www.deitel.com/training/

and subscribe to the free Deitel® Buzz Online e-mail newsletter at:

www.deitel.com/newsletter/subscribe.html

Individuals wishing to purchase Deitel books, and LiveLessons DVD and web-based training courses can do so through www.deitel.com. Bulk orders by corporations, the government, the military and academic institutions should be placed directly with Pearson. For more information, visit

www.prenhall.com/mischtm/support.html#order
..................Content has been hidden....................

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