C# for Programmers

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

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:

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

Generics, Collections

GUI/Windows® Forms OOP: Classes, Inheritance, and Polymorphism OOD/UML™ ATM Case Study Graphics and Multimedia Multithreading Exception Handling And more... VISIT WWW.DEITEL.COM Download code examples To receive updates on this book, subscribe to the free DEITEL® BUZZ ONLINE e-mail newsletter at www.deitel.com/newsletter/subscribe.html Read archived Issues of the DEITEL® BUZZ ONLINE Get corporate training information

Author(s): Harvey Deitel; Paul Deitel
Series: Deitel Developer Series
Edition: 2
Publisher: Prentice Hall PTR
Year: 2005

Language: English
Pages: 1317
Tags: coding, programming, computer science, mathematics, logic, math, maths

Contents
Preface
1 Introduction to Computers, the Internet and Visual C#
1.1 Introduction
1.2 Microsoft’s Windows® Operating System
1.3 C#
1.4 The Internet and the World Wide Web
1.5 Extensible Markup Language (XML)
1.6 Microsoft’s .NET
1.7 The .NET Framework and the Common Language Runtime
1.8 Test-Driving a C# Application
1.9 (Only Required Section of the Case Study) Software Engineering Case Study: Introduction to Object Technology and the UML
1.10 Wrap-Up
1.11 Web Resources
2 Introduction to the Visual C# 2005 Express Edition IDE
2.1 Introduction
2.2 Overview of the Visual Studio 2005 IDE
2.3 Menu Bar and Toolbar
2.4 Navigating the Visual Studio 2005 IDE
2.4.1 Solution Explorer
2.4.2 Toolbox
2.4.3 Properties Window
2.5 Using Help
2.6 Using Visual Programming to Create a Simple Program Displaying Text and an Image
2.7 Wrap-Up
2.8 Web Resources
3 Introduction to C# Applications
3.1 Introduction
3.2 A Simple C# Application: Displaying a Line of Text
3.3 Creating Your Simple Application in Visual C# Express
3.4 Modifying Your Simple C# Application
3.5 Formatting Text with Console.Write and Console.WriteLine
3.6 Another C# Application: Adding Integers
3.7 Memory Concepts
3.8 Arithmetic
3.9 Decision Making: Equality and Relational Operators
3.10 (Optional) Software Engineering Case Study: Examining the ATM Requirements Document
3.11 Wrap-Up
4 Introduction to Classes and Objects
4.1 Introduction
4.2 Classes, Objects, Methods, Properties and Instance Variables
4.3 Declaring a Class with a Method and Instantiating an Object of a Class
4.4 Declaring a Method with a Parameter
4.5 Instance Variables and Properties
4.6 UML Class Diagram with a Property
4.7 Software Engineering with Properties and set and get Accessors
4.8 Value Types vs. Reference Types
4.9 Initializing Objects with Constructors
4.10 Floating-Point Numbers and Type decimal
4.11 (Optional) Software Engineering Case Study: Identifying the Classes in the ATM Requirements Document
4.12 Wrap-Up
5 Control Statements: Part 1
5.1 Introduction
5.2 Control Structures
5.3 if Single-Selection Statement
5.4 if…else Double-Selection Statement
5.5 While Repetition Statement
5.6 Formulating Algorithms: Counter-Controlled Repetition
5.7 Formulating Algorithms: Sentinel-Controlled Repetition
5.8 Formulating Algorithms: Nested Control Statements
5.9 Compound Assignment Operators
5.10 Increment and Decrement Operators
5.11 Simple Types
5.12 (Optional) Software Engineering Case Study: Identifying Class Attributes in the ATM System
5.13 Wrap-Up
6 Control Statements: Part 2
6.1 Introduction
6.2 Essentials of Counter-Controlled Repetition
6.3 for Repetition Statement
6.4 Examples Using the for Statement
6.5 do…while Repetition Statement
6.6 switch Multiple-Selection Statement
6.7 break and continue Statements
6.8 Logical Operators
6.9 (Optional) Software Engineering Case Study: Identifying Objects’ States and Activities in the ATM System
6.10 Wrap-Up
7 Methods: A Deeper Look
7.1 Introduction
7.2 Packaging Code in C#
7.3 static Methods, static Variables and Class Math
7.4 Declaring Methods with Multiple Parameters
7.5 Notes on Declaring and Using Methods
7.6 Method Call Stack and Activation Records
7.7 Argument Promotion and Casting
7.8 The Framework Class Library
7.9 Case Study: Random-Number Generation
7.9.1 Scaling and Shifting Random Numbers
7.9.2 Random-Number Repeatability for Testing and Debugging
7.10 Case Study: A Game of Chance (Introducing Enumerations)
7.11 Scope of Declarations
7.12 Method Overloading
7.13 Recursion
7.14 Passing Arguments: Pass-by-Value vs. Pass-by-Reference
7.15 (Optional) Software Engineering Case Study: Identifying Class Operations in the ATM System
7.16 Wrap-Up
8 Arrays
8.1 Introduction
8.2 Arrays
8.3 Declaring and Creating Arrays
8.4 Examples Using Arrays
8.5 Case Study: Card Shuffling and Dealing Simulation
8.6 foreach Statement
8.7 Passing Arrays and Array Elements to Methods
8.8 Passing Arrays by Value and by Reference
8.9 Case Study: Class GradeBook Using an Array to Store Grades
8.10 Multidimensional Arrays
8.11 Case Study: Class GradeBook Using a Rectangular Array
8.12 Variable-Length Argument Lists
8.13 Using Command-Line Arguments
8.14 (Optional) Software Engineering Case Study: Collaboration Among Objects in the ATM System
8.15 Wrap-Up
9 Classes and Objects: A Deeper Look
9.1 Introduction
9.2 Time Class Case Study
9.3 Controlling Access to Members
9.4 Referring to the Current Object’s Members with the this Reference
9.5 Indexers
9.6 Time Class Case Study: Overloaded Constructors
9.7 Default and Parameterless Constructors
9.8 Composition
9.9 Garbage Collection and Destructors
9.10 static Class Members
9.11 readonly Instance Variables
9.12 Software Reusability
9.13 Data Abstraction and Encapsulation
9.14 Time Class Case Study: Creating Class Libraries
9.15 internal Access
9.16 Class View and Object Browser
9.17 (Optional) Software Engineering Case Study: Starting to Program the Classes of the ATM System
9.18 Wrap-Up
10 Object-Oriented Programming: Inheritance
10.1 Introduction
10.2 Base Classes and Derived Classes
10.3 protected Members
10.4 Relationship between Base Classes and Derived Classes
10.4.1 Creating and Using a CommissionEmployee Class
10.4.2 Creating a BasePlusCommissionEmployee Class without Using Inheritance
10.4.3 Creating a CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy
10.4.4 CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using protected Instance Variables
10.4.5 CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using private Instance Variables
10.5 Constructors in Derived Classes
10.6 Software Engineering with Inheritance
10.7 Class object
10.8 Wrap-Up
11 Polymorphism, Interfaces & Operator Overloading
11.1 Introduction
11.2 Polymorphism Examples
11.3 Demonstrating Polymorphic Behavior
11.4 Abstract Classes and Methods
11.5 Case Study: Payroll System Using Polymorphism
11.5.1 Creating Abstract Base Class Employee
11.5.2 Creating Concrete Derived Class SalariedEmployee
11.5.3 Creating Concrete Derived Class HourlyEmployee
11.5.4 Creating Concrete Derived Class CommissionEmployee
11.5.5 Creating Indirect Concrete Derived Class BasePlusCommissionEmployee
11.5.6 Polymorphic Processing, Operator is and Downcasting
11.5.7 Summary of the Allowed Assignments Between Base Class and Derived Class Variables
11.6 sealed Methods and Classes
11.7 Case Study: Creating and Using Interfaces
11.7.1 Developing an IPayable Hierarchy
11.7.2 Declaring Interface IPayable
11.7.3 Creating Class Invoice
11.7.4 Modifying Class Employee to Implement Interface IPayable
11.7.5 Modifying Class SalariedEmployee for Use in the IPayable Hierarchy
11.7.6 Using Interface IPayable to Process Invoices and Employees Polymorphically
11.7.7 Common Interfaces of the .NET Framework Class Library
11.8 Operator Overloading
11.9 (Optional) Software Engineering Case Study: Incorporating Inheritance and Polymorphism into the ATM System
11.10 Wrap-Up
12 Exception Handling
12.1 Introduction
12.2 Exception Handling Overview
12.3 Example: Divide by Zero Without Exception Handling
12.4 Example: Handling DivideByZeroExceptions and FormatExceptions
12.4.1 Enclosing Code in a try Block
12.4.2 Catching Exceptions
12.4.3 Uncaught Exceptions
12.4.4 Termination Model of Exception Handling
12.4.5 Flow of Control When Exceptions Occur
12.5 .NET Exception Hierarchy
12.5.1 Classes ApplicationException and SystemException
12.5.2 Determining Which Exceptions a Method Throws
12.6 finally Block
12.7 Exception Properties
12.8 User-Defined Exception Classes
12.9 Wrap-Up
13 Graphical User Interface Concepts: Part 1
13.1 Introduction
13.2 Windows Forms
13.3 Event Handling
13.3.1 A Simple Event-Driven GUI
13.3.2 Another Look at the Visual Studio Generated Code
13.3.3 Delegates and the Event-Handling Mechanism
13.3.4 Other Ways to Create Event Handlers
13.3.5 Locating Event Information
13.4 Control Properties and Layout
13.5 Labels, TextBoxes and Buttons
13.6 GroupBoxes and Panels
13.7 CheckBoxes and RadioButtons
13.8 PictureBoxes
13.9 ToolTips
13.10 NumericUpDown Control
13.11 Mouse-Event Handling
13.12 Keyboard-Event Handling
13.13 Wrap-Up
14 Graphical User Interface Concepts: Part 2
14.1 Introduction
14.2 Menus
14.3 MonthCalendar Control
14.4 DateTimePicker Control
14.5 LinkLabel Control
14.6 ListBox Control
14.7 CheckedListBox Control
14.8 ComboBox Control
14.9 TreeView Control
14.10 ListView Control
14.11 TabControl Control
14.12 Multiple Document Interface (MDI) Windows
14.13 Visual Inheritance
14.14 User-Defined Controls
14.15 Wrap-Up
15 Multithreading
15.1 Introduction
15.2 Thread States: Life Cycle of a Thread
15.3 Thread Priorities and Thread Scheduling
15.4 Creating and Executing Threads
15.5 Thread Synchronization and Class Monitor
15.6 Producer/Consumer Relationship without Thread Synchronization
15.7 Producer/Consumer Relationship with Thread Synchronization
15.8 Producer/Consumer Relationship: Circular Buffer
15.9 Multithreading with GUIs
15.10 Wrap-Up
16 Strings, Characters and Regular Expressions
16.1 Introduction
16.2 Fundamentals of Characters and Strings
16.3 string Constructors
16.4 string Indexer, Length Property and CopyTo Method
16.5 Comparing strings
16.6 Locating Characters and Substrings in strings
16.7 Extracting Substrings from strings
16.8 Concatenating strings
16.9 Miscellaneous string Methods
16.10 Class StringBuilder
16.11 Length and Capacity Properties, EnsureCapacity Method and Indexer of Class StringBuilder
16.12 Append and AppendFormat Methods of Class StringBuilder
16.13 Insert, Remove and Replace Methods of Class StringBuilder
16.14 Char Methods
16.15 Card Shuffling and Dealing Simulation
16.16 Regular Expressions and Class Regex
16.16.1 Regular Expression Example
16.16.2 Validating User Input with Regular Expressions
16.16.3 Regex methods Replace and Split
16.17 Wrap-Up
17 Graphics and Multimedia
17.1 Introduction
17.2 Drawing Classes and the Coordinate System
17.3 Graphics Contexts and Graphics Objects
17.4 Color Control
17.5 Font Control
17.6 Drawing Lines, Rectangles and Ovals
17.7 Drawing Arcs
17.8 Drawing Polygons and Polylines
17.9 Advanced Graphics Capabilities
17.10 Introduction to Multimedia
17.11 Loading, Displaying and Scaling Images
17.12 Animating a Series of Images
17.13 Windows Media Player
17.14 Microsoft Agent
17.15 Wrap-Up
18 Files and Streams
18.1 Introduction
18.2 Data Hierarchy
18.3 Files and Streams
18.4 Classes File and Directory
18.5 Creating a Sequential-Access Text File
18.6 Reading Data from a Sequential-Access Text File
18.7 Serialization
18.8 Creating a Sequential-Access File Using Object Serialization
18.9 Reading and Deserializing Data from a Sequential-Access Text File
18.10 Wrap-Up
19 Extensible Markup Language (XML)
19.1 Introduction
19.2 XML Basics
19.3 Structuring Data
19.4 XML Namespaces
19.5 Document Type Definitions (DTDs)
19.6 W3C XML Schema Documents
19.7 (Optional) Extensible Stylesheet Language and XSL Transformations
19.8 (Optional) Document Object Model (DOM)
19.9 (Optional) Schema Validation with Class XmlReader
19.10 (Optional) XSLT with Class XslCompiledTransform
19.11 Wrap-Up
19.12 Web Resources
20 Database, SQL and ADO.NET
20.1 Introduction
20.2 Relational Databases
20.3 Relational Database Overview: Books Database
20.4 SQL
20.4.1 Basic SELECT Query
20.4.2 WHERE Clause
20.4.3 ORDER BY Clause
20.4.4 Merging Data from Multiple Tables: INNER JOIN
20.4.5 INSERT Statement
20.4.6 UPDATE Statement
20.4.7 DELETE Statement
20.5 ADO.NET Object Model
20.6 Programming with ADO.NET: Extracting Information from a Database
20.6.1 Displaying a Database Table in a DataGridView
20.6.2 How Data Binding Works
20.7 Querying the Books Database
20.8 Programming with ADO.NET: Address Book Case Study
20.9 Using a DataSet to Read and Write XML
20.10 Wrap-Up
20.11 Web Resources
21 ASP.NET 2.0, Web Forms and Web Controls
21.1 Introduction
21.2 Simple HTTP Transactions
21.3 Multitier Application Architecture
21.4 Creating and Running a Simple Web-Form Example
21.4.1 Examining an ASPX File
21.4.2 Examining a Code-Behind File
21.4.3 Relationship Between an ASPX File and a Code-Behind File
21.4.4 How the Code in an ASP.NET Web Page Executes
21.4.5 Examining the XHTML Generated by an ASP.NET Application
21.4.6 Building an ASP.NET Web Application
21.5 Web Controls
21.5.1 Text and Graphics Controls
21.5.2 AdRotator Control
21.5.3 Validation Controls
21.6 Session Tracking
21.6.1 Cookies
21.6.2 Session Tracking with HttpSessionState
21.7 Case Study: Connecting to a Database in ASP.NET
21.7.1 Building a Web Form That Displays Data from a Database
21.7.2 Modifying the Code-Behind File for the Guestbook Application
21.8 Case Study: Secure Books Database Application
21.8.1 Examining the Completed Secure Books Database Application
21.8.2 Creating the Secure Books Database Application
21.9 Wrap-Up
21.10 Web Resources
22 Web Services
22.1 Introduction
22.2 .NET Web Services Basics
22.2.1 Creating a Web Service in Visual Web Developer
22.2.2 Discovering Web Services
22.2.3 Determining a Web Service’s Functionality
22.2.4 Testing a Web Service’s Methods
22.2.5 Building a Client to Use a Web Service
22.3 Simple Object Access Protocol (SOAP)
22.4 Publishing and Consuming Web Services
22.4.1 Defining the HugeInteger Web Service
22.4.2 Building a Web Service in Visual Web Developer
22.4.3 Deploying the HugeInteger Web Service
22.4.4 Creating a Client to Consume the HugeInteger Web Service
22.4.5 Consuming the HugeInteger Web Service
22.5 Session Tracking in Web Services
22.5.1 Creating a Blackjack Web Service
22.5.2 Consuming the Blackjack Web Service
22.6 Using Web Forms and Web Services
22.6.1 Adding Data Components to a Web Service
22.6.2 Creating a Web Form to Interact with the Airline Reservation Web Service
22.7 User-Defined Types in Web Services
22.8 Wrap-Up
22.9 Web Resources
23 Networking: Streams-Based Sockets and Datagrams
23.1 Introduction
23.2 Connection-Oriented vs. Connectionless Communication
23.3 Protocols for Transporting Data
23.4 Establishing a Simple TCP Server (Using Stream Sockets)
23.5 Establishing a Simple TCP Client (Using Stream Sockets)
23.6 Client/Server Interaction with Stream-Socket Connections
23.7 Connectionless Client/Server Interaction with Datagrams
23.8 Client/Server Tic-Tac-Toe Using a Multithreaded Server
23.9 WebBrowser Control
23.10 .NET Remoting
23.11 Wrap-Up
24 Data Structures
24.1 Introduction
24.2 Simple-Type structs, Boxing and Unboxing
24.3 Self-Referential Classes
24.4 Linked Lists
24.5 Stacks
24.6 Queues
24.7 Trees
24.7.1 Binary Search Tree of Integer Values
24.7.2 Binary Search Tree of IComparable Objects
24.8 Wrap-Up
25 Generics
25.1 Introduction
25.2 Motivation for Generic Methods
25.3 Generic Method Implementation
25.4 Type Constraints
25.5 Overloading Generic Methods
25.6 Generic Classes
25.7 Notes on Generics and Inheritance
25.8 Wrap-Up
26 Collections
26.1 Introduction
26.2 Collections Overview
26.3 Class Array and Enumerators
26.4 Non-Generic Collections
26.4.1 Class ArrayList
26.4.2 Class Stack
26.4.3 Class Hashtable
26.5 Generic Collections
26.5.1 Generic Class SortedDictionary
26.5.2 Generic Class LinkedList
26.6 Synchronized Collections
26.7 Wrap-Up
A: Operator Precedence Chart
B: Number Systems
B.1 Introduction
B.2 Abbreviating Binary Numbers as Octal and Hexadecimal Numbers
B.3 Converting Octal and Hexadecimal Numbers to Binary Numbers
B.4 Converting from Binary, Octal or Hexadecimal to Decimal
B.5 Converting from Decimal to Binary, Octal or Hexadecimal
B.6 Negative Binary Numbers: Two’s Complement Notation
C: Using the Visual Studio; 2005 Debugger
C.1 Introduction
C.2 Breakpoints and the Continue Command
C.3 The Locals and Watch Windows
C.4 Controlling Execution Using the Step Into, Step Over, Step Out and Continue Commands
C.5 Other Features
C.5.1 Edit and Continue
C.5.2 Exception Assistant
C.5.3 Just My Code™ Debugging
C.5.4 Other New Debugger Features
C.6 Wrap-Up
D: ASCII Character Set
E: Unicode
E.1 Introduction
E.2 Unicode Transformation Formats
E.3 Characters and Glyphs
E.4 Advantages/Disadvantages of Unicode
E.5 Using Unicode
E.6 Character Ranges
F: Introduction to XHTML: Part 1
F.1 Introduction
F.2 Editing XHTML
F.3 First XHTML Example
F.4 W3C XHTML Validation Service
F.5 Headers
F.6 Linking
F.7 Images
F.8 Special Characters and More Line Breaks
F.9 Unordered Lists
F.10 Nested and Ordered Lists
F.11 Web Resources
G: Introduction to XHTML: Part 2
G.1 Introduction
G.2 Basic XHTMLTables
G.3 Intermediate XHTML Tables and Formatting
G.4 Basic XHTML Forms
G.5 More Complex XHTML Forms
G.6 Internal Linking
G.7 Creating and Using Image Maps
G.8 meta Elements
G.9 frameset Element
G.10 Nested framesets
G.11 Web Resources
H: HTML/XHTML Special Characters
I: HTML/XHTML Colors
J: ATM Case Study Code
J.1 ATM Case Study Implementation
J.2 Class ATM
J.3 Class Screen
J.4 Class Keypad
J.5 Class CashDispenser
J.6 Class DepositSlot
J.7 Class Account
J.8 Class BankDatabase
J.9 Class Transaction
J.10 Class BalanceInquiry
J.11 Class Withdrawal
J.12 Class Deposit
J.13 Class ATMCaseStudy
J.14 Wrap-Up
K: UML 2: Additional Diagram Types
K.1 Introduction
K.2 Additional Diagram Types
L: Simple Types
Index
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z