- Shopping Bag ( 0 items )
A new edition of this title is available, ISBN-10: 0137144156 ISBN-13: 9780137144150
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,
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#,
The DEITEL® Developer Series is designed for practicing programmers. The series presents focused treatments of emerging technologies, including .NET, J2EE, Web services, and more.
Pre-publication Reviewer Testimonials
"Excellent coverage of developing ASP.NET 2.0 applications, with plenty of sample code. The chapter on exception handling is one of, if not the best such chapters I have seen in the 50+ .NET related books I've read and reviewed. The chapter on Networking is one of the best I have seen."
—Peter Bromberg, Merrill Lynch, C# MVP
"A comprehensive introduction to
—Gavin Osborne, Saskatchewan Institute of Applied Science and Technology
"A superb job of clearly integrating the theory of relational databases and SQL with ADO.NET!"
—Harlan Brewer, University of Cincinnati
"Excellent introduction to .NET collections."
—José Antonio González Seco, Andalucia's Parlamient
"A beautiful presentation of threads."
—Pavel Tsekov, Caesar BSC
"The ATM OOD/UML case study is excellent! The implementation of the design developed in the early chapters gives the reader a fantastic model of a real world problem. You hit a home run with this one!"
—Catherine Wyman, Devry-Phoenix
Practical, Example-Rich Coverage Of:
"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:
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 email@example.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:
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.
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
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.
We include many case studies, some spanning multiple sections and chapters:
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 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.
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.
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.
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.
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.
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.
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.
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.
|1||Introduction to computers, the Internet and Visual C#||1|
|2||Introduction to the Visual C# 2005 Express Edition IDE||18|
|3||Introduction to C# applications||51|
|4||Introduction to classes and objects||92|
|5||Control statements : part 1||129|
|6||Control statements : part 2||160|
|7||Methods : a deeper look||195|
|9||Classes and objects : a deeper look||294|
|10||Object-oriented programming : inheritance||342|
|11||Polymorphism, interfaces & operator overloading||381|
|13||Graphical user interface concepts : part 1||460|
|14||Graphical user interface concepts : part 2||504|
|16||Strings, characters and regular expressions||607|
|17||Graphics and multimedia||647|
|18||Files and streams||707|
|19||Extensible markup language (XML)||753|
|20||Database, SQL and ADO.NET||808|
|21||ASP.NET 2.0, Web forms and Web controls||859|
|23||Networking : streams-based sockets and datagrams||1022|
|A||Operator precedence chart||1162|
|C||Using the Visual Studio 2005 debugger||1174|
|D||ASCII character set||1191|
|F||Introduction to XHTML : part 1||1200|
|G||Introduction to XHTML : part 2||1221|
|H||HTML/XHTML special characters||1252|
|J||ATM case study code||1256|
|K||UML 2 : additional diagram types||1283|