The practicing programmer's DEITEL? guide to C# and the powerful Microsoft .NET Framework

Written for programmers with a background in C++, Java, or other high-level languages, this book applies the Deitel signature live-code approach to teaching programming and explores Microsoft's C# language and the new .NET 2.0 in depth. The book is updated for Visual Studio? 2005 and C# 2.0, and presents C# concepts in the context of fully tested programs, complete with syntax shading, ...

See more details below
C# for Programmers

Available on NOOK devices and apps  
  • NOOK Devices
  • NOOK HD/HD+ Tablet
  • NOOK
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac
  • NOOK Study

Want a NOOK? Explore Now

NOOK Book (eBook)
BN.com price
(Save 42%)$47.99 List Price


The practicing programmer's DEITEL® guide to C# and the powerful Microsoft .NET Framework

Written for programmers with a background in C++, Java, or other high-level languages, this book applies the Deitel signature live-code approach to teaching programming and explores Microsoft's C# language and the new .NET 2.0 in depth. The book is updated for Visual Studio® 2005 and C# 2.0, and presents C# concepts in the context of fully tested programs, complete with syntax shading, detailed line-by-line code descriptions, and program outputs. The book features 200+ C# applications with 16,000+ lines of proven C# code, as well as 300+ programming tips that will help you build robust applications.

Start with a concise introduction to C# fundamentals using an early classes and objects approach, then rapidly move on to more advanced topics, including multithreading, XML, ADO.NET 2.0, ASP.NET 2.0, Web services, network programming, and .NET remoting. Along the way you will enjoy the Deitels' classic treatment of object-oriented programming and a new, OOD/UML™ ATM case study, including a complete C# implementation. When you are finished, you will have everything you need to build next-generation Windows applications, Web applications, and Web services.

Dr. Harvey M. Deitel and Paul J. Deitel are the founders of Deitel & Associates, Inc., the internationally recognized programming languages content-creation and corporate-training organization. Together with their colleagues at Deitel & Associates, Inc., they have written many international best-selling programming languages textbooks that millions of people worldwide have used to master C, C++, Java™, C#, XML, Visual Basic®, Perl, Python, and Internet and Web programming.

The DEITEL® Developer Series is designed for practicing programmers. The series presents focused treatments of emerging technologies, including .NET, J2EE, Web services, and more.

Practical, Example-Rich Coverage Of:

  • C# 2.0, .NET 2.0, FCL
  • ASP.NET 2.0, Web Forms and Controls
  • Database, SQL, and ADO.NET 2.0
  • Networking and .NET Remoting
  • XML, Web Services
  • Generics, Collections
  • GUI/Windows® Forms
  • OOP: Classes, Inheritance, and Polymorphism
  • OOD/UML™ ATM Case Study
  • Graphics and Multimedia
  • Multithreading
  • Exception Handling
  • And more...


  • Download code examples
  • To receive updates on this book, subscribe to the free DEITEL® BUZZ ONLINE e-mail newsletter at deitel.com/newsletter/subscribe.html
  • Read archived Issues of the DEITEL® BUZZ ONLINE
  • Get corporate training information
Read More Show Less

Product Details

  • ISBN-13: 9780132465915
  • Publisher: Pearson Education
  • Publication date: 12/5/2005
  • Sold by: Barnes & Noble
  • Format: eBook
  • Edition number: 2
  • Pages: 1360
  • File size: 56 MB
  • Note: This product may take a few minutes to download.

Meet the Author

Harvey M. Deitel and Paul J. Deitel are the founders of Deitel & Associates, Inc., the internationally recognized programming languages content-creation and corporate training organization. Together with their colleagues at Deitel & Associates, Inc., they have written many international best-selling programming languages textbooks and professional books that millions of people worldwide have used to master C, C++, Java™, C#, XML, Visual Basic®, Perl, Python, and Internet and Web programming.

Paul J. Deitel and Harvey M. Deitel are the founders of Deitel & Associates, Inc., the internationally recognized programming languages content-creation and corporate training organization. Together with their colleagues at Deitel & Associates, Inc., they have written many international best-selling programming languages textbooks and professional books that millions of people worldwide have used to master C, C++, Java™, C#, XML, Visual Basic®, Perl, Python, and Internet and Web programming.

Read More Show Less

Read an Excerpt

"Live in fragments no longer, only connect."
—Edgar Morgan Forster

Welcome to C# and the world of Windows, Internet and Web programming with Visual Studio 2005 and the .NET 2.0 platform! This book presents leading-edge computing technologies to software developers and IT professionals.

At Deitel & Associates, we write computer science textbooks for college students and professional books for software developers. We also teach this material in industry seminars at organizations worldwide.

This book was a joy to create. To start, we put the previous edition under the microscope:

  • We audited our C# presentation against the most recent Ecma and Microsoft C# Language Specifications, which can be found at www.ecma-international.org/ publications/standards/Ecma-334.html and msdn.microsoft.com/vcsharp/ programming/language/, respectively.
  • All of the chapters have been significantly updated and upgraded.
  • We changed to an early classes and objects pedagogy. Now readers build reusable classes starting in Chapter 4.
  • We updated our object-oriented presentation to use the latest version of the UML (Unified Modeling Language)—UML™ 2.0—the industry-standard graphical language for modeling object-oriented systems.
  • We added an optional OOD/UML automated teller machine (ATM) case study in Chapters 1, 3-9 and 11. The case study includes a complete C# code implementation of the ATM.
  • We added several multi-section object-oriented programming case studies.
  • We incorporated key new features of Microsoft's latest release of C#—Visual C# 2005—and added discussions on generics, .NET remoting and debugging.
  • We significantly enhanced our treatment of

All of this has been carefully scrutinized by a team of distinguished .NET industry developers, academic professionals and members of the Microsoft C# development team.

Who Should Read This Book

We have several C# publications, intended for different audiences.

C# for Programmers, 2/e, is part of the Deitel® Developer Series, intended for professional software developers who want a deep treatment of a new technology with minimal introductory material. The book emphasizes achieving program clarity through the proven techniques of structured programming, object-oriented programming (OOP) and event-driven programming. It continues with upper-level topics such as

How to Program Series college textbooks, the Deitel® Developer Series books do not include the extensive pedagogic features and ancillary support materials required for college courses.

C# for Programmers, 2/e presents many complete, working C# programs and depicts their inputs and outputs in actual screen shots of running programs. This is our signature "live-code" approach—we present concepts in the context of complete working programs. The book's source code is available free for download at www.deitel.com/books/csharpforprogrammers2/. We assume in our Chapter 1 "test-drive" instructions that you extract these examples to the C:\ folder on your computer. This will create an examples folder that contains subfolders for each chapter (e.g., ch01, ch02, etc.).

As you read this book, if you have questions, send an e-mail to deitel@deitel.com; we will respond promptly. For updates on this book and the status of C# software, and for the latest news on all Deitel publications and services, please visit www.deitel.com regularly and be sure to sign up for the free Deitel® Buzz Online e-mail newsletter at www.deitel.com/newsletter/subscribe.html.

Downloading Microsoft Visual C# 2005 Express Edition Software

Microsoft makes available a free version of its C# development tool called the Visual C# 2005 Express Edition. You may use it to compile the example programs in the book. You can download the Visual C# 2005 Express Edition and the Visual Web Developer 2005 Express Edition at:

Microsoft provides a dedicated forum for help using the Express Editions:

We provide updates on the status of this software at www.deitel.com and in our free e-mail newsletter www.deitel.com/newsletter/subscribe.html.

Features in C# for Programmers, 2/e

This new edition contains many new and enhanced features.

Updated for Visual Studio 2005, C# 2.0 and .NET 2.0

We updated the entire text to reflect Microsoft's latest release of Visual C# 2005. New items include:

  • Screenshots updated to the Visual Studio 2005 IDE.
  • Property accessors with different access modifiers.
  • Viewing exception data with the Exception Assistant (a new feature of the Visual Studio 2005 Debugger).
  • Using drag-and-drop techniques to create data-bound windows forms in ADO.NET 2.0.
  • Using the Data Sources window to create application-wide data connections.
  • Using a BindingSource to simplify the process of binding controls to an underlying data source.
  • Using a BindingNavigator to enable simple navigation, insertion, deletion and editing of database data on a Windows Form.
  • Using the Master Page Designer to create a common look and feel for ASP.NET Web pages.
  • Using Visual Studio 2005 smart tag menus to perform many of the most common programming tasks when new controls are dragged onto a Windows Form or ASP.NET Web page.
  • Using Visual Web Developer's built-in Web server to test ASP.NET 2.0 applications and Web services.
  • Using an
  • Using a SqlDataSource to bind a SQL Server database to a control or set of controls.
  • Using an ObjectDataSource to bind a control to an object that serves as a data source.
  • Using the ASP.NET 2.0 login and create new user controls to personalize access to Web applications.
  • Using generics and generic collections to create general models of methods and classes that can be declared once, but used with many types of data.
  • Using generic collections from the Systems.Collections.Generic namespace.
New Interior Design

Working with the creative services team at Prentice Hall, we redesigned the interior styles for our Deitel Developer Series books. In response to reader requests, we now place the key terms and the index's page reference for each defining occurrence in bold italic text for easier reference. We emphasize on-screen components in the bold Helvetica font and emphasize C# program text in the Lucida font.

Syntax Shading

We syntax shade all the C# code, similar to the way most C# integrated-development environments and code editors syntax color code. This greatly improves code readability— an especially important goal, given that this book contains 16,800+ lines of code. Our syntax-shading conventions are as follows:

comments appear in italic keywords appear in bold, italic errors and JSP scriptlet delimiters appear in bold, black constants and literal values appear in bold, gray all other code appears in plain, black

Code Highlighting

Extensive code highlighting makes it easy for readers to spot each program's featured code segments—we place light gray rectangles around the key code.

Early Classes and Objects Approach

We still introduce the basic object-technology concepts and terminology in Chapter 1. In the previous edition, we developed custom classes in Chapter 9, but in this edition, we start doing that in our new Chapter 4. Chapters 5-8 have been carefully rewritten from an "early classes and objects approach."

Carefully Tuned Treatment of Object-Oriented Programming in Chapters 9-11 We performed a high-precision upgrade of C# for Programmers, 2/e. This edition is clearer and more accessible—especially if you are new to object-oriented programming (OOP). We completely rewrote the OOP chapters, integrating an employee payroll class hierarchy case study and motivating interfaces with an accounts payable hierarchy.

Case Studies

We include many case studies, some spanning multiple sections and chapters:

  • The GradeBook class in Chapters 4, 5, 6 and 8.
  • The optional, OOD/UML ATM system in the Software Engineering sections of Chapters 1, 3-9 and 11.
  • The Time class in several sections of Chapter 9.
  • The Employee payroll application in Chapters 10 and 11.
  • The GuestBook ASP.NET application in Chapter 21.
  • The secure book database ASP.NET application in Chapter 21.
  • The airline reservation Web service in Chapter 22.
Integrated GradeBook Case Study

To reinforce our early classes presentation, we present an integrated case study using classes and objects in Chapters 4-6 and 8. We incrementally build a GradeBook class that represents an instructor's grade book and performs various calculations based on a set of student grades—finding the average, finding the maximum and minimum, and printing a bar chart. Our goal is to familiarize you with the important concepts of objects and classes through a real-world example of a substantial class. We develop this class from the ground up, constructing methods from control statements and carefully developed algorithms, and adding instance variables and arrays as needed to enhance the functionality of the class.

The Unified Modeling Language (UML)—Using the UML 2.0 to Develop an Object-Oriented Design of an ATM

The Unified Modeling Language™ (UML™) has become the preferred graphical modeling language for designing object-oriented systems. All the UML diagrams in the book comply with the UML 2.0 specification. We use UML class diagrams to visually represent classes and their inheritance relationships, and we use UML activity diagrams to demonstrate the flow of control in each of C#'s several control statements.

This Second Edition includes a new, optional (but highly recommended) case study on object-oriented design using the UML. The case study was reviewed by a distinguished team of OOD/UML academic and industry professionals, including leaders in the field from Rational (the creators of the UML and now a division of IBM) and the Object Management Group (responsible for maintaining and evolving the UML). In the case study, we design and fully implement the software for a simple automatic teller machine (ATM). The Software Engineering Case Study sections at the ends of Chapters 1, 3-9 and 11 present a carefully paced introduction to object-oriented design using the UML. We introduce a concise, simplified subset of the UML 2.0, then guide the reader through a first design experience intended for the novice object-oriented designer/programmer. The case study is not an exercise; rather, it is an end-to-end learning experience that concludes with a detailed walkthrough of the complete C# code. The Software Engineering Case Study sections help readers develop an object-oriented design to complement the object-oriented programming concepts they begin learning in Chapter 1 and implementing in Chapter 4. In the first of these sections at the end of Chapter 1, we introduce basic OOD concepts and terminology. In the optional Software Engineering Case Study sections at the ends of Chapters 3-6, we consider more substantial issues, as we undertake a challenging problem with the techniques of OOD. We analyze a typical requirements document that specifies a system to be built, determine the classes needed to implement that system, determine the attributes the classes need to have, determine the behaviors the classes need to exhibit and specify how the classes must interact with one another to meet the system requirements. In Appendix J, we include a complete C# implementation of the object-oriented system that we design in the earlier chapters. We employ a carefully developed, incremental object-oriented design process to produce a UML model for our ATM system. From this design, we produce a substantial working C# implementation using key programming notions, including classes, objects, encapsulation, visibility, composition, inheritance and polymorphism.

Web Forms, Web Controls and ASP.NET 2.0

The .NET platform enables developers to create robust, scalable Web-based applications. Microsoft's .NET server-side technology, Active Server Pages (ASP) .NET, allows programmers to build Web documents that respond to client requests. To enable interactive Web pages, server-side programs process information users input into HTML forms. ASP .NET provides enhanced visual programming capabilities, similar to those used in building Windows forms for desktop programs. Programmers can create Web pages visually, by dragging and dropping Web controls onto Web forms. Chapter 21, ASP.NET, Web Forms and Web Controls, introduces these powerful technologies.

Web Services and ASP.NET 2.0

Microsoft's .NET strategy embraces the Internet and Web as integral to software development and deployment. Web services technology enables information sharing, e-commerce and other interactions using standard Internet protocols and technologies, such as Hypertext Transfer Protocol (HTTP), Extensible Markup Language (

Object-Oriented Programming

Object-oriented programming is the most widely employed technique for developing robust, reusable software. This text offers a rich treatment of C#'s object-oriented programming features. Chapter 4, introduces how to create classes and objects. These concepts are extended in Chapter 9. Chapter 10 discusses how to create powerful new classes quickly by using inheritance to "absorb" the capabilities of existing classes. Chapter 11 familiarizes the reader with the crucial concepts of polymorphism, abstract classes, concrete classes and interfaces, which facilitate powerful manipulations among objects belonging to an inheritance hierarchy.

Use of the Extensible Markup Language (


Databases store vast amounts of information that individuals and organizations must access to conduct business. As an evolution of Microsoft's ActiveX Data Objects (ADO) technology, ADO.NET represents a new approach for building applications that interact with databases. ADO.NET uses

Visual Studio 2005 Debugger

In Appendix C we explain how to use key debugger features, such as setting "breakpoints' and "watches," stepping into and out of methods, and examining the method call stack.

Teaching Approach

C# for Programmers, 2/e contains a rich collection of examples that have been tested on Windows 2000 and Windows XP. The book concentrates on the principles of good software engineering and stresses program clarity. We avoid arcane terminology and syntax specifications in favor of teaching by example. We are educators who teach leading-edge topics in industry classrooms worldwide. Dr. Harvey M. Deitel has 20 years of college teaching experience and 15 years of industry teaching experience. Paul Deitel has 12 years of industry teaching experience and is an experienced corporate trainer, having taught courses at all levels to government, industry, military and academic clients of Deitel & Associates.

Learning C# via the Live-Code Approach

C# for Programmers 2/e, is loaded with live-code examples—each new concept is presented in the context of a complete working C# application that is immediately followed by one or more sample executions showing the program's inputs and outputs. This style exemplifies the way we teach and write about programming. We call this method of teaching and writing the live-code approach. We use programming languages to teach programming languages.

World Wide Web Access

All of the source-code examples for C# for Programmers, 2/e, (and for our other publications) are available on the Internet as downloads from the following Web sites:

Registration is quick and easy, and the downloads are free. Download all the examples, then run each program as you read the corresponding text discussions. Making changes to the examples and immediately seeing the effects of those changes is a great way to enhance your C# learning experience.


Each chapter begins with a statement of objectives.


The learning objectives are followed by quotations. Some are humorous, philosophical or offer interesting insights.


The chapter outline helps you approach the material in a top-down fashion, so you can anticipate what is to come, and set a comfortable and effective learning pace.

16,875 Lines of Code in 213 Example Programs (with Program Outputs)

Our live-code programs range in size from just a few lines of code to substantial examples containing hundreds of lines of code (e.g., our ATM system implementation contains 655 lines of code). Each program is followed by a window containing the outputs produced when the program is run, so you can confirm that the programs run as expected. Our programs demonstrate the diverse features of C#. The code is syntax shaded, with C# keywords, comments and other program text emphasized with variations of bold, italic and gray text. This facilitates reading the code, especially when you're reading the larger programs.

700 Illustrations/Figures

An abundance of charts, tables, line drawings, programs and program outputs is included. We model the flow of control in control statements with UML activity diagrams. UML class diagrams model the fields, constructors and methods of classes. We use additional types of UML diagrams throughout our optional OOD/UML ATM case study.

316 Programming Tips

We include programming tips to emphasize important aspects of program development. We highlight these tips in the form of Good Programming Practices, Common Programming Errors, Error-Prevention Tips, Look-and-Feel Observations, Performance Tips, Portability Tips and Software Engineering Observations. These tips and practices represent the best we have gleaned from a combined six decades of programming and teaching experience. This approach is like the highlighting of axioms, theorems and corollaries in mathematics books; it provides a basis on which to build good software.

Good Programming Practice

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

Common Programming Error

Developers learning a language tend to make certain kinds of errors frequently. Pointing out these Common Programming Errors reduces the likelihood that readers will make the same mistakes.

Error-Prevention Tip

When we first designed this tip type, we thought the tips would contain suggestions strictly for exposing bugs and removing them from programs. In fact, many of the tips describe aspects of C# that prevent bugs from getting into programs in the first place, thus simplifying the testing and debugging processes.

Look-and-Feel Observation

We provide Look-and-Feel Observations to highlight graphical-user-interface conventions. These observations help you design attractive, user-friendly graphical user interfaces that conform to industry norms.

Performance Tip

Developers like to "turbo charge" their programs. We include Performance Tips that highlight opportunities for improving program performance—making programs run faster or minimizing the amount of memory that they occupy.

Portability Tip

We include Portability Tips to help you write portable code and to explain how C# achieves its high degree of portability.

Software Engineering Observation

The object-oriented programming paradigm necessitates a complete rethinking of the way we build software systems. C# is an effective language for achieving good software engineering. The Software Engineering Observations highlight architectural and design issues that affect the construction of software systems, especially large-scale systems.

Wrap-Up Section

Each chapter ends with a brief "wrap-up" section that recaps the chapter content and transitions to the next chapter.

Approximately 5500 Index Entries

We have included an extensive index which is especially useful to developers who use the book as a reference.

"Double Indexing" of C# Live-Code Examples

C# for Programmers, 2/e has 213 live-code examples, which we have double indexed. For every source-code program in the book, we indexed the figure caption both alphabetically and as a subindex item under "Examples." This makes it easier to find examples using particular features.

A Tour of the Optional Case Study on Object-Oriented Design with the UML

In this section we tour the book's optional case study on object-oriented design with the UML. This tour previews the contents of the nine Software Engineering Case Study sections (in Chapters 1, 3-9 and 11). After completing this case study, you will be thoroughly familiar with an object-oriented design and implementation for a significant C# application.

The design presented in the ATM case study was developed at Deitel & Associates, Inc. and scrutinized by industry professionals. Our primary goal throughout the design process was to create a simple design that would be clear to OOD and UML novices, while still demonstrating key OOD concepts and the related UML modeling techniques.

Section 1.9—(Only Required Section of the Case Study) Software Engineering Case Study: Introduction to Object Technology and the UML—introduces the object-oriented design case study with the UML. The section presents the basic concepts and terminology of object technology, including classes, objects, encapsulation, inheritance and polymorphism. We discuss the history of the UML. This is the only required section of the case study.

Section 3.10—(Optional) Software Engineering Case Study: Examining the ATM Requirements Document—discusses a requirements document that specifies the requirements for a system that we will design and implement—the software for a simple automated teller machine (ATM). We investigate the structure and behavior of object-oriented systems in general. We discuss how the UML will facilitate the design process in subsequent Software Engineering Case Study sections by providing several additional types of diagrams to model our system. We include a list of URLs and book references on object-oriented design with the UML. We discuss the interaction between the ATM system specified by the requirements document and its user. Specifically, we investigate the scenarios that may occur between the user and the system itself—these are called use cases. We model these interactions, using UML use case diagrams.

Section 4.11—(Optional) Software Engineering Case Study: Identifying the Classes in the ATM Requirements Documents—begins to design the ATM system. We identify its classes by extracting the nouns and noun phrases from the requirements document. We arrange these classes into a UML class diagram that describes the class structure of our simulation. The class diagram also describes relationships, known as associations, among classes.

Section 5.12—(Optional) Software Engineering Case Study: Identifying Class Attributes in the ATM System—focuses on the attributes of the classes discussed in Section 3.10. A class contains both attributes (data) and operations (behaviors). As we see in later sections, changes in an object's attributes often affect the object's behavior. To determine the attributes for the classes in our case study, we extract the adjectives describing the nouns and noun phrases (which defined our classes) from the requirements document, then place the attributes in the class diagram we created in Section 3.10.

Section 6.9—(Optional) Software Engineering Case Study: Identifying Objects' States and Activities in the ATM System—discusses how an object, at any given time, occupies a specific condition called a state. A state transition occurs when that object receives a message to change state. The UML provides the state machine diagram, which identifies the set of possible states that an object may occupy and models that object's state transitions. An object also has an activity—the work it performs in its lifetime. The UML provides the activity diagram—a flowchart that models an object's activity. In this section, we use both types of diagrams to begin modeling specific behavioral aspects of our ATM system, such as how the ATM carries out a withdrawal transaction and how the ATM responds when the user is authenticated.

Section 7.15—(Optional) Software Engineering Case Study: Identifying Class Operations in the ATM System—identifies the operations, or services, of our classes. We extract from the requirements document the verbs and verb phrases that specify the operations for each class. We then modify the class diagram of Section 3.10 to include each operation with its associated class. At this point in the case study, we will have gathered all information possible from the requirements document. However, as future chapters introduce such topics as inheritance, we will modify our classes and diagrams.

Section 8.14—(Optional) Software Engineering Case Study: Collaboration Among Objects in the ATM System—provides a "rough sketch" of the model for our ATM system. In this section, we see how it works. We investigate the behavior of the simulation by discussing collaborations—messages that objects send to each other to communicate. The class operations that we discovered in Section 6.9 turn out to be the collaborations among the objects in our system. We determine the collaborations, then collect them into a communication diagram—the UML diagram for modeling collaborations. This diagram reveals which objects collaborate and when. We present a communication diagram of the collaborations among objects to perform an ATM balance inquiry. We then present the UML sequence diagram for modeling interactions in a system. This diagram emphasizes the chronological ordering of messages. A sequence diagram models how objects in the system interact to carry out withdrawal and deposit transactions.

Section 9.17—(Optional) Software Engineering Case Study: Starting to Program the Classes of the ATM System—takes a break from designing the behavior of our system. We begin the implementation process to emphasize the material discussed in Chapter 8. Using the UML class diagram of Section 3.10 and the attributes and operations discussed in Section 4.11 and Section 6.9, we show how to implement a class in C# from a design. We do not implement all classes—because we have not completed the design process. Working from our UML diagrams, we create code for the Withdrawal class.

Section 11.9—(Optional) Software Engineering Case Study: Incorporating Inheritance and Polymorphism into the ATM System—continues our discussion of object-oriented programming. We consider inheritance—classes sharing common characteristics may inherit attributes and operations from a "base" class. In this section, we investigate how our ATM system can benefit from using inheritance. We document our discoveries in a class diagram that models inheritance relationships—the UML refers to these relationships as generalizations. We modify the class diagram of Section 3.10 by using inheritance to group classes with similar characteristics. This section concludes the design of the model portion of our simulation. We implement this model as C# code in Appendix J.

Appendix J—ATM Case Study Code—The majority of the case study involved designing the model (i.e., the data and logic) of the ATM system. In this appendix, we implement that model in C#. Using all the UML diagrams we created, we present the C# classes necessary to implement the model.

Read More Show Less

Table of Contents

Preface xxiii Chapter1: Introduction to Computers, the Internet and Visual C# 1

1.1 Introduction 2
1.2 Microsoft's Windows® Operating System 2
1.3 C# 3
1.4 The Internet and the World Wide Web 4
1.5 Extensible Markup Language (XML) 5
1.6 Microsoft's .NET 5
1.7 The .NET Framework and the Common Language Runtime 6
1.8 Test-Driving a C# Application 8
1.9 (Only Required Section of the Case Study) Software Engineering Case Study: Introduction to Object Technology and the UML 10
1.10 Wrap-Up 16
1.11 Web Resources 16

Chapter 2: Introduction to the Visual C# 2005 Express Edition IDE 18

2.1 Introduction 19
2.2 Overview of the Visual Studio 2005 IDE 19
2.3 Menu Bar and Toolbar 25
2.4 Navigating the Visual Studio 2005 IDE 27
2.5 Using Help 35
2.6 Using Visual Programming to Create a Simple Program Displaying Text and an Image 37
2.7 Wrap-Up 49
2.8 Web Resources 50

Chapter 3: Introduction to C# Applications 51

3.1 Introduction 52
3.2 A Simple C# Application: Displaying a Line of Text 52
3.3 Creating Your Simple Application in Visual C# Express 58
3.4 Modifying Your Simple C# Application 65
3.5 Formatting Text with Console.Write and Console.WriteLine 67
3.6 Another C# Application: Adding Integers 68
3.7 Memory Concepts 72
3.8 Arithmetic 73
3.9 Decision Making: Equality and Relational Operators 77
3.10 (Optional) Software Engineering Case Study: Examining the ATM Requirements Document 81
3.11 Wrap-Up 91

Chapter 4: Introduction to Classes and Objects 92

4.1 Introduction 93
4.2 Classes, Objects, Methods, Properties and Instance Variables 93
4.3 Declaring a Class with a Method and Instantiating an Object of a Class 95
4.4 Declaring a Method with a Parameter 99
4.5 Instance Variables and Properties 102
4.6 UML Class Diagram with a Property 107
4.7 Software Engineering with Properties and set and get Accessors 108
4.8 Value Types vs. Reference Types 109
4.9 Initializing Objects with Constructors 111
4.10 Floating-Point Numbers and Type decimal 113
4.11 (Optional) Software Engineering Case Study: Identifying the Classes in the ATM Requirements Document 120
4.12 Wrap-Up 127

Chapter 5: Control Statements: Part 1 129

5.1 Introduction 130
5.2 Control Structures 130
5.3 if Single-Selection Statement 133
5.4 if... else Double-Selection Statement 134
5.5 while Repetition Statement 137
5.6 Formulating Algorithms: Counter-Controlled Repetition 139
5.7 Formulating Algorithms: Sentinel-Controlled Repetition 143
5.8 Formulating Algorithms: Nested Control Statements 147
5.9 Compound Assignment Operators 150
5.10 Increment and Decrement Operators 151
5.11 Simple Types 154
5.12 (Optional) Software Engineering Case Study: Identifying Class Attributes in the ATM System 154
5.13 Wrap-Up 159

Chapter 6: Control Statements: Part 2 160

6.1 Introduction 161
6.2 Essentials of Counter-Controlled Repetition 161
6.3 for Repetition Statement 163
6.4 Examples Using the for Statement 167
6.5 do... while Repetition Statement 172
6.6 switch Multiple-Selection Statement 173
6.7 break and continue Statements 181
6.8 Logical Operators 183
6.9 (Optional) Software Engineering Case Study: IdentifyingObjects' States and Activities in the ATM System 189
6.10 Wrap-Up 193

Chapter 7: Methods: A Deeper Look 195

7.1 Introduction 196
7.2 Packaging Code in C# 197
7.3 static Methods, static Variables and Class Math 197
7.4 Declaring Methods with Multiple Parameters 200
7.5 Notes on Declaring and Using Methods 204
7.6 Method Call Stack and Activation Records 205
7.7 Argument Promotion and Casting 206
7.8 The Framework Class Library 208
7.9 Case Study: Random-Number Generation 209
7.10 Case Study: A Game of Chance (Introducing Enumerations) 215
7.11 Scope of Declarations 219
7.12 Method Overloading 222
7.13 Recursion 225
7.14 Passing Arguments: Pass-by-Value vs. Pass-by-Reference 228
7.15 (Optional) Software Engineering Case Study: Identifying Class Operations in the ATM System 232
7.16 Wrap-Up 239

Chapter 8: Arrays 241

8.1 Introduction 242
8.2 Arrays 242
8.3 Declaring and Creating Arrays 244
8.4 Examples Using Arrays 245
8.5 Case Study: Card Shuffling and Dealing Simulation 253
8.6 foreach Statement 257
8.7 Passing Arrays and Array Elements to Methods 259
8.8 Passing Arrays by Value and by Reference 261
8.9 Case Study: Class GradeBook Using an Array to Store Grades 265
8.10 Multidimensional Arrays 271
8.11 Case Study: Class GradeBook Using a Rectangular Array 276
8.12 Variable-Length Argument Lists 281
8.13 Using Command-Line Arguments 283
8.14 (Optional) Software Engineering Case Study: Collaboration Among Objects in the ATM System 285
8.15 Wrap-Up 293

Chapter 9: Classes and Objects: A Deeper Look 294

9.1 Introduction 295
9.2 Time Class Case Study 296
9.3 Controlling Access to Members 299
9.4 Referring to the Current Object's Members with the this Reference 300
9.5 Indexers 303
9.6 Time Class Case Study: Overloaded Constructors 306
9.7 Default and Parameterless Constructors 312
9.8 Composition 312
9.9 Garbage Collection and Destructors 316
9.10 static Class Members 317
9.11 readonly Instance Variables 322
9.12 Software Reusability 324
9.13 Data Abstraction and Encapsulation 325
9.14 Time Class Case Study: Creating Class Libraries 327
9.15 internal Access 331
9.16 Class View and Object Browser 3339.17 (Optional) Software Engineering Case Study: Starting to Program the Classes of the ATM System 3349.18 Wrap-Up 341

Chapter 10: Object-Oriented Programming: Inheritance 342

10.1 Introduction 343
10.2 Base Classes and Derived Classes 344
10.3 protected Members 346
10.4 Relationship between Base Classes and Derived Classes 347
10.5 Constructors in Derived Classes 372
10.6 Software Engineering with Inheritance 376
10.7 Class object 378
10.8 Wrap-Up 380

Chapter 11: Polymorphism, Interfaces & Operator Overloading 381

11.1 Introduction 382
11.2 Polymorphism Examples 384
11.3 Demonstrating Polymorphic Behavior 385
11.4 Abstract Classes and Methods 388
11.5 Case Study: Payroll System Using Polymorphism 390
11.6 sealed Methods and Classes 405
11.7 Case Study: Creating and Using Interfaces 406
11.8 Operator Overloading 416
11.9 (Optional) Software Engineering Case Study: Incorporating Inheritance and Polymorphism into the ATM System 421
11.10 Wrap-Up 429

Chapter 12: Exception Handling 431

12.1 Introduction 432
12.2 Exception Handling Overview 433
12.3 Example: Divide by Zero Without Exception Handling 433
12.4 Example: Handling DivideByZeroExceptions and FormatExceptions 436
12.5 .NET Exception Hierarchy 442
12.6 finally Block 443
12.7 Exception Properties 451
12.8 User-Defined Exception Classes 456
12.9 Wrap-Up 459

Chapter 13: Graphical User Interface Concepts: Part 1 460

13.1 Introduction 461
13.2 Windows Forms 463
13.3 Event Handling 465
13.4 Control Properties and Layout 472
13.5 Labels, TextBoxes and Buttons 476
13.6 GroupBoxes and Panels 479
13.7 CheckBoxes and RadioButtons 482
13.8 PictureBoxes 490
13.9 ToolTips 492
13.10 NumericUpDown Control 495
13.11 Mouse-Event Handling 497
13.12 Keyboard-Event Handling 500
13.13 Wrap-Up 503

Chapter 14: Graphical User Interface Concepts: Part 2 504

14.1 Introduction 505
14.2 Menus 505
14.3 MonthCalendar Control 515
14.4 DateTimePicker Control 515
14.5 LinkLabel Control 519
14.6 ListBox Control 523
14.7 CheckedListBox Control 527
14.8 ComboBox Control 530
14.9 TreeView Control 534
14.10 ListView Control 540
14.11 TabControl Control 546
14.12 Multiple Document Interface (MDI) Windows 551
14.13 Visual Inheritance 559
14.14 User-Defined Controls 562
14.15 Wrap-Up 565

Chapter 15: Multithreading 567

15.1 Introduction 568
15.2 Thread States: Life Cycle of a Thread 569
15.3 Thread Priorities and Thread Scheduling 571
15.4 Creating and Executing Threads 573
15.5 Thread Synchronization and Class Monitor 576
15.6 Producer/Consumer Relationship without Thread Synchronization 578
15.7 Producer/Consumer Relationship with Thread Synchronization 585
15.8 Producer/Consumer Relationship: Circular Buffer 593
15.9 Multithreading with GUIs 601
15.10 Wrap-Up 606

Chapter 16: Strings, Characters and Regular Expressions 607

16.1 Introduction 608
16.2 Fundamentals of Characters and Strings 609
16.3 string Constructors 610
16.4 string Indexer, Length Property and CopyTo Method 611
16.5 Comparing strings 613
16.6 Locating Characters and Substrings in strings 616
16.7 Extracting Substrings from strings 618
16.8 Concatenating strings 619
16.9 Miscellaneous string Methods 619
16.10 Class StringBuilder 621
16.11 Length and Capacity Properties, EnsureCapacity Method and Indexer of Class StringBuilder 623
16.12 Append and AppendFormat Methods of Class StringBuilder 625
16.13 Insert, Remove and Replace Methods of Class StringBuilder 627
16.14 Char Methods 630
16.15 Card Shuffling and Dealing Simulation 632
16.16 Regular Expressions and Class Regex 636
16.17 Wrap-Up 646

Chapter 17: Graphics and Multimedia 647

17.1 Introduction 648
17.2 Drawing Classes and the Coordinate System 648
17.3 Graphics Contexts and Graphics Objects 650
17.4 Color Control 651
17.5 Font Control 658
17.6 Drawing Lines, Rectangles and Ovals 663
17.7 Drawing Arcs 666
17.8 Drawing Polygons and Polylines 669
17.9 Advanced Graphics Capabilities 672
17.10 Introduction to Multimedia 677
17.11 Loading, Displaying and Scaling Images 678
17.12 Animating a Series of Images 680
17.13 Windows Media Player 691
17.14 Microsoft Agent 692
17.15 Wrap-Up 706

Chapter 18: Files and Streams 707

18.1 Introduction 708
18.2 Data Hierarchy 708
18.3 Files and Streams 710
18.4 Classes File and Directory 711
18.5 Creating a Sequential-Access Text File 720
18.6 Reading Data from a Sequential-Access Text File 731
18.7 Serialization 741
18.8 Creating a Sequential-Access File Using Object Serialization 742
18.9 Reading and Deserializing Data from a Sequential-Access Text File 748
18.10 Wrap-Up 752

Chapter 19: Extensible Markup Language (XML) 753

19.1 Introduction 754
19.2 XML Basics 754
19.3 Structuring Data 757
19.4 XML Namespaces 764
19.5 Document Type Definitions (DTDs) 767
19.6 W3C XML Schema Documents 770
19.7 (Optional) Extensible Stylesheet Language and XSL Transformations 777
19.8 (Optional) Document Object Model (DOM) 786
19.9 (Optional) Schema Validation with Class XmlReader 800
19.10 (Optional) XSLT with Class XslCompiledTransform 803
19.11 Wrap-Up 806
19.12 Web Resources 806

Chapter 20: Database, SQL and ADO.NET 808

20.1 Introduction 809
20.2 Relational Databases 810
20.3 Relational Database Overview: Books Database 811
20.4 SQL 815
20.5 ADO.NET Object Model 824
20.6 Programming with ADO.NET: Extracting Information from a Database 825
20.7 Querying the Books Database 837
20.8 Programming with ADO.NET: Address Book Case Study 846
20.9 Using a DataSet to Read and Write XML 854
20.10 Wrap-Up 857
20.11 Web Resources 857

Chapter 21: ASP.NET 2.0,Web Forms andWeb Controls 859

21.1 Introduction 860
21.2 Simple HTTP Transactions 861
21.3 Multitier Application Architecture 863
21.4 Creating and Running a Simple Web-Form Example 864
21.5 Web Controls 879
21.6 Session Tracking 901
21.7 Case Study: Connecting to a Database in ASP.NET 919
21.8 Case Study: Secure Books Database Application 931
21.9 Wrap-Up 960
21.10 Web Resources 961

Chapter 22: Web Services 962

22.1 Introduction 963
22.2 .NET Web Services Basics 964
22.3 Simple Object Access Protocol (SOAP) 971
22.4 Publishing and Consuming Web Services 973
22.5 Session Tracking in Web Services 989
22.6 Using Web Forms and Web Services 1003
22.7 User-Defined Types in Web Services 1011
22.8 Wrap-Up 1021
22.9 Web Resources 1021

Chapter 23: Networking: Streams-Based Sockets and Datagrams 1022

23.1 Introduction 1023
23.2 Connection-Oriented vs. Connectionless Communication 1024
23.3 Protocols for Transporting Data 1024
23.4 Establishing a Simple TCP Server (Using Stream Sockets) 1025
23.5 Establishing a Simple TCP Client (Using Stream Sockets) 1027
23.6 Client/Server Interaction with Stream-Socket Connections 1027
23.7 Connectionless Client/Server Interaction with Datagrams 1038
23.8 Client/Server Tic-Tac-Toe Using a Multithreaded Server 1043
23.9 WebBrowser Control 1058
23.10 .NET Remoting 1061
23.11 Wrap-Up 1073

Chapter 24: Data Structures 1074

24.1 Introduction 1075
24.2 Simple-Type structs, Boxing and Unboxing 1075
24.3 Self-Referential Classes 1076
24.4 Linked Lists 1078
24.5 Stacks 1090
24.6 Queues 1094
24.7 Trees 1098
24.8 Wrap-Up 1112

Chapter 25: Generics 1114

25.1 Introduction 1115
25.2 Motivation for Generic Methods 1116
25.3 Generic Method Implementation 1118
25.4 Type Constraints 1120
25.5 Overloading Generic Methods 1123
25.6 Generic Classes 1124
25.7 Notes on Generics and Inheritance 1133
25.8 Wrap-Up 1133

Chapter 26: Collections 1134

26.1 Introduction 1135
26.2 Collections Overview 1136
26.3 Class Array and Enumerators 1138
26.4 Non-Generic Collections 1142
26.5 Generic Collections 1153
26.6 Synchronized Collections 1160
26.7 Wrap-Up 1161

Appendix A: Operator Precedence Chart 1162 Appendix B: Number Systems 1164

B.1 Introduction 1165
B.2 Abbreviating Binary Numbers as Octal and Hexadecimal Numbers 1168
B.3 Converting Octal and Hexadecimal Numbers to Binary Numbers 1169
B.4 Converting from Binary, Octal or Hexadecimal to Decimal 1169
B.5 Converting from Decimal to Binary, Octal or Hexadecimal 1170
B.6 Negative Binary Numbers: Two's Complement Notation 1172

Appendix C: Using the Visual Studio® 2005 Debugger 1174

C.1 Introduction 1175
C.2 Breakpoints and the Continue Command 1175
C.3 The Locals and Watch Windows 1180
C.4 Controlling Execution Using the Step Into, Step Over, Step Out and Continue Commands 1183
C.5 Other Features 1186
C.6 Wrap-Up 1190

Appendix D: ASCII Character Set 1191 Appendix E: Unicode® 1192

E.1 Introduction 1193
E.2 Unicode Transformation Formats 1194
E.3 Characters and Glyphs 1195
E.4 Advantages/Disadvantages of Unicode 1195
E.5 Using Unicode 1196
E.6 Character Ranges 1198

Appendix F: Introduction to XHTML: Part 1 1200

F.1 Introduction 1201
F.2 Editing XHTML 1201
F.3 First XHTML Example 1202
F.4 W3C XHTML Validation Service 1205
F.5 Headers 1206
F.6 Linking 1208
F.7 Images 1210
F.8 Special Characters and More Line Breaks 1214
F.9 Unordered Lists 1216
F.10 Nested and Ordered Lists 1218
F.11 Web Resources 1220

Appendix G: Introduction to XHTML: Part 2 1221

G.1 Introduction 1222
G.2 Basic XHTML Tables 1222
G.3 Intermediate XHTML Tables and Formatting 1225
G.4 Basic XHTML Forms 1227
G.5 More Complex XHTML Forms 1230
G.6 Internal Linking 1237
G.7 Creating and Using Image Maps 1240
G.8 meta Elements 1243
G.9 frameset Element 1245
G.10 Nested framesets 1249
G.11 Web Resources 1251

Appendix H: HTML/XHTML Special Characters 1252 Appendix I: HTML/XHTML Colors 1253 Appendix J: ATM Case Study Code 1256

J.1 ATM Case Study Implementation 1256
J.2 Class ATM 1257
J.3 Class Screen 1263
J.4 Class Keypad 1264
J.5 Class CashDispenser 1264
J.6 Class DepositSlot 1266
J.7 Class Account 1266
J.8 Class BankDatabase 1269
J.9 Class Transaction 1271
J.10 Class BalanceInquiry 1273
J.11 Class Withdrawal 1274
J.12 Class Deposit 1278
J.13 Class ATMCaseStudy 1281
J.14 Wrap-Up 1281

Appendix K: UML 2: Additional Diagram Types 1283

K.1 Introduction 1283
K.2 Additional Diagram Types 1283

Appendix L: Simple Types 1285 Index 1287

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)