C# for Programmers / Edition 2

C# for Programmers / Edition 2

by Harvey M. Deitel, Paul J. Deitel
     
 

View All Available Formats & Editions

ISBN-10: 0131345915

ISBN-13: 9780131345911

Pub. Date: 12/06/2005

Publisher: Prentice Hall

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

Overview

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

Product Details

ISBN-13:
9780131345911
Publisher:
Prentice Hall
Publication date:
12/06/2005
Series:
Deitel Developer Series
Edition description:
REV
Pages:
1360
Product dimensions:
6.92(w) x 9.18(h) x 2.46(d)

Table of Contents

Preface xxiiiChapter1: 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 (

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 (

19.1 Introduction 754
19.2

19.3 Structuring Data 757
19.4

19.5 Document Type Definitions (DTDs) 767
19.6 W3C

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

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

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 1162Appendix 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 1191Appendix 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 1252Appendix I: HTML/XHTML Colors 1253Appendix 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 1285Index 1287

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >