did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

We're the #1 textbook rental company. Let us show you why.

9780132618205

C# 2010 for Programmers

by ;
  • ISBN13:

    9780132618205

  • ISBN10:

    0132618206

  • Edition: 4th
  • Format: Paperback
  • Copyright: 2010-10-29
  • Publisher: Prentice Hall
  • View Upgraded Edition
  • Purchase Benefits
  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $59.99

Summary

The professional programmer’s Deitel® guide to C# 2010 and the powerful Microsoft® .NET 4 Framework

Written for programmers with a background in C++, Java or other high-level, object-oriented languages, this book applies the Deitel signature live-code approach to teaching programming and explores Microsoft’s C# 2010 language and .NET 4 in depth. The book is updated for Visual Studio® 2010 and C# 4, 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 17,000+ lines of proven C# code, as well as hundreds of 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, .NET 4, LINQ, WPF, ASP.NET 4, WCF web services and Silverlight®. Along the way you’ll enjoy the Deitels’ classic treatment of object-oriented programming and the OOD/UML® ATM case study, including a complete C# implementation. When you’re finished, you’ll be ready to build next-generation Windows applications, web applications and web services.

Check out the related LiveLessons video product, C# 2010 Fundamentals: Parts I, II and III, containing 20+ hours of video synchronized to this book: www.deitel.com/livelessons.

-Practical, example-rich coverage of:

-.NET 4, Types, Arrays, Exception Handling

-LINQ, Object/Collection Initializers

-OOP: Classes, Objects, Inheritance, Polymorphism, Interfaces

-WinForms, WPF, XAML, Event Handling

-WPF GUI/Graphics/Multimedia

-Silverlight®

-Lists, Queues, Stacks, Trees

-Generic Collections, Methods and Classes

-XML®, LINQ to XML

-Database, LINQ to SQL

-ASP.NET 4.0, ASP.NET AJAX

-Web Forms, Web Controls

-WCF Web Services

-OOD/UML® Case Study

Visit www.deitel.com

-For information on Deitel’s Dive Into® training courses offered worldwide visit www.deitel.com/training

-To license Deitel book and/or LiveLessons video content for your learning management system, e-mail deitel@deitel.com

-Download code examples

-Follow Deitel on Twitter® @deitel and Facebook® at www.deitel.com/deitelfan/

-To receive updates for this book, subscribe to the free Deite® Buzz Online e-mail newsletter at www.deitel.com/newsletter/subscribe.html

Author Biography

Paul Deitel and Harvey Deitel are the founders of Deitel & Associates, Inc., the internationally recognized programming languages authoring and corporate-training organization. Millions of people worldwide have used Deitel books and LiveLessons videos to master C#, C++, Java™, C, iPhone app development, Internet and web programming, JavaScript, XML, Visual Basic®, Visual C++®, Perl, Python and more. Paul Deitel is also a Microsoft C# MVP.

Table of Contents

Preface      xxi

Before You Begin       xxxiv


Chapter 1: Introduction        1

1.1   Introduction    2

1.2   Microsoft’s Windows® Operating System    2

1.3   C, C++, Objective-C and Java    3

1.4   C# 3

1.5   Extensible Markup Language (XML)   4

1.6   Introduction to Microsoft .NET   4

1.7   The .NET Framework and the Common Language Runtime   4

1.8   Test-Driving the Advanced Painter Application   5

1.9   Introduction to Object Technology   8

1.10 Wrap-Up   10

 

Chapter 2: Dive Into® Visual C# 2010 Express      11

2.1 Introduction   12

2.2 Overview of the Visual Studio 2010 IDE   12

2.3 Menu Bar and Toolbar   17

2.4 Navigating the Visual Studio IDE   19

2.5 Using Help   24

2.6 Using Visual Programming to Create a Simple Program that Displays Text and an Image   27

2.7 Wrap-Up   38

2.8 Web Resources   39

 

Chapter 3: Introduction to C# Applications          40

3.1 Introduction   41

3.2 A Simple C# Application: Displaying a Line of Text   41

3.3 Creating a Simple Application in Visual C# Express 46

3.4 Modifying Your Simple C# Application 53

3.5 Formatting Text with Console.Write and Console.WriteLine 56

3.6 Another C# Application: Adding Integers 57

3.7 Arithmetic 59

3.8 Decision Making: Equality and Relational Operators 61

3.9 Wrap-Up 65

 

Chapter 4: Introduction to Classes and Objects       66

4.1   Introduction   67

4.2   Classes, Objects, Methods, Properties and Instance Variables   67

4.3   Declaring a Class with a Method and Instantiating an Object of a Class   68

4.4   Declaring a Method with a Parameter   72

4.5   Instance Variables and Properties   75

4.6   UML Class Diagram with a Property   80

4.7   Software Engineering with Properties and set and get Accessors   81

4.8   Auto-Implemented Properties  82

4.9   Value Types vs. Reference Types   83

4.10 Initializing Objects with Constructors   84

4.11 Floating-Point Numbers and Type decimal   87

4.12 Wrap-Up   93

 

Chapter 5: Control Statements: Part 1       94

5.1   Introduction   95

5.2   Control Structures   95

5.3   if Single-Selection Statement   97

5.4   if…else Double-Selection Statement   98

5.5   while Repetition Statement   102

5.6   Counter-Controlled Repetition   103

5.7   Sentinel-Controlled Repetition   107

5.8   Nested Control Statements   112

5.9   Compound Assignment Operators   115

5.10 Increment and Decrement Operators   115

5.11 Simple Types   118

5.12 Wrap-Up   119

 

Chapter 6: Control Statements: Part 2         120

6.1 Introduction   121

6.2 Essentials of Counter-Controlled Repetition   121

6.3 for Repetition Statement   122

6.4 Examples Using the for Statement   127

6.5 do…while Repetition Statement   131

6.6 switch Multiple-Selection Statement   132

6.7 break and continue Statements   140

6.8 Logical Operators   142

6.9 Wrap-Up   148

 

Chapter 7: Methods: A Deeper Look        149

7.1   Introduction   150

7.2   Packaging Code in C#   150

7.3   static Methods, static Variables and Class Math   151

7.4   Declaring Methods with Multiple Parameters   154

7.5   Notes on Declaring and Using Methods   157

7.6   Method-Call Stack and Activation Records   158

7.7   Argument Promotion and Casting   159

7.8   The .NET Framework Class Library   160

7.9   Case Study: Random-Number Generation   162

7.10 Case Study: A Game of Chance (Introducing Enumerations)   167

7.11 Scope of Declarations   172

7.12 Method Overloading   174

7.13 Optional Parameters   177

7.14 Named Parameters   178

7.15 Recursion   179

7.16 Passing Arguments: Pass-by-Value vs. Pass-by-Reference   182

7.17 Wrap-Up   185

 

Chapter 8: Arrays         187

8.1   Introduction   188

8.2   Arrays   188

8.3   Declaring and Creating Arrays   189

8.4   Examples Using Arrays   190

8.5  Case Study: Card Shuffling and Dealing Simulation   199

8.6   foreach Statement   203

8.7   Passing Arrays and Array Elements to Methods   205

8.8   Passing Arrays by Value and by Reference   208

8.9   Case Study: Class GradeBook Using an Array to Store Grades   212

8.10 Multidimensional Arrays   217

8.11 Case Study: GradeBook Using a Rectangular Array   222

8.12 Variable-Length Argument Lists   227

8.13 Using Command-Line Arguments   229

8.14 Wrap-Up   231

 

Chapter 9: Introduction to LINQ and the List Collection      232

9.1 Introduction   233

9.2 Querying an Array of int Values Using LINQ   234

9.3 Querying an Array of Employee Objects Using LINQ   238

9.4 Introduction to Collections   243

9.5 Querying a Generic Collection Using LINQ   246

9.6 Wrap-Up   248

9.7 Deitel LINQ Resource Center   248

 

Chapter 10: Classes and Objects: A Deeper Look        249

10.1   Introduction   250

10.2   Time Class Case Study   250

10.3   Controlling Access to Members   254

10.4   Referring to the Current Object’s Members with the this Reference   255

10.5   Indexers   257

10.6   Time Class Case Study: Overloaded Constructors   261

10.7   Default and Parameterless Constructors   267

10.8   Composition   267

10.9   Garbage Collection and Destructors   270

10.10 static Class Members   271

10.11 readonly Instance Variables   275

10.12 Data Abstraction and Encapsulation   276

10.13 Time Class Case Study: Creating Class Libraries   277

10.14 internal Access   282

10.15 Class View and Object Browser   283

10.16 Object Initializers   285

10.17 Time Class Case Study: Extension Methods   288

10.18 Delegates   291

10.19 Lambda Expressions   293

10.20 Anonymous Types   296

10.21 Wrap-Up   298

 

Chapter 11: Object-Oriented Programming: Inheritance       300

11.1 Introduction   301

11.2 Base Classes and Derived Classes   302

11.3 protected Members   304

11.4 Relationship between Base Classes and Derived Classes   305

11.5 Constructors in Derived Classes   329

11.6 Software Engineering with Inheritance   329

11.7 Class object   330

11.8 Wrap-Up   331

 

Chapter 12: OOP: Polymorphism, Interfaces and Operator Overloading         332

12.1 Introduction   333

12.2 Polymorphism Examples   335

12.3 Demonstrating Polymorphic Behavior   336

12.4 Abstract Classes and Methods   339

12.5 Case Study: Payroll System Using Polymorphism   341

12.6 sealed Methods and Classes   357

12.7 Case Study: Creating and Using Interfaces   357

12.8 Operator Overloading   368

12.9 Wrap-Up   371

 

Chapter 13: Exception Handling         372

13.1 Introduction   373

13.2 Example: Divide by Zero without Exception Handling   373

13.3 Example: Handling DivideByZeroExceptions and FormatExceptions   376

13.4 .NET Exception Hierarchy   381

13.5 finally Block   383

13.6 The using Statement   389

13.7 Exception Properties   390

13.8 User-Defined Exception Classes   395

13.9 Wrap-Up   398

 

Chapter 14: Graphical User Interfaces with Windows Forms: Part 1         399

14.1   Introduction   400

14.2   Windows Forms   401

14.3   Event Handling   403

14.4   Control Properties and Layout   410

14.5   Labels, TextBoxes and Buttons  414

14.6   GroupBoxes and Panels   417

14.7   CheckBoxes and RadioButtons   420

14.8   PictureBoxes   428

14.9   ToolTips   430

14.10 NumericUpDown Control   432

14.11 Mouse-Event Handling   434

14.12 Keyboard-Event Handling   437

14.13 Wrap-Up   440

 

Chapter 15: Graphical User Interfaces with Windows Forms: Part 2        441

15.1   Introduction  442

15.2   Menus   442

15.3   MonthCalendar Control   451

15.4   DateTimePicker Control   452

15.5   LinkLabel Control   455

15.6   ListBox Control   459

15.7   CheckedListBox Control   463

15.8   ComboBox Control   466

15.9   TreeView Control   470

15.10 ListView Control   475

15.11 TabControl Control   481

15.12 Multiple Document Interface (MDI) Windows   486

15.13 Visual Inheritance   493

15.14 User-Defined Controls   498

15.15 Wrap-Up   502

 

Chapter 16: Strings and Characters           504

16.1   Introduction   505

16.2   Fundamentals of Characters and Strings   506

16.3   string Constructors   507

16.4   string Indexer, Length Property and CopyTo Method   508

16.5   Comparing strings   509

16.6   Locating Characters and Substrings in strings   512

16.7   Extracting Substrings from strings   515

16.8   Concatenating strings   516

16.9   Miscellaneous string Methods   517

16.10 Class StringBuilder   518

16.11 Length and Capacity Properties, EnsureCapacity Method and Indexer of Class StringBuilder   519

16.12 Append and AppendFormat Methods of Class StringBuilder   521

16.13 Insert, Remove and Replace Methods of Class StringBuilder   523

16.14 Char Methods   526

16.15 Regular Expressions   528

16.16 Wrap-Up   542

 

Chapter 17: Files and Streams           543

17.1   Introduction   544

17.2   Data Hierarchy   544

17.3   Files and Streams   546

17.4   Classes File and Directory   547

17.5   Creating a Sequential-Access Text File   556

17.6   Reading Data from a Sequential-Access Text File   565

17.7   Case Study: Credit Inquiry Program   569

17.8   Serialization   575

17.9   Creating a Sequential-Access File Using Object Serialization   576

17.10 Reading and Deserializing Data from a Binary File   580

17.11 Wrap-Up   582

 

Chapter 18: Databases and LINQ          584

18.1   Introduction   585

18.2   Relational Databases   586

18.3   A Books Database   587

18.4   LINQ to SQL   590

18.5   Querying a Database with LINQ   591

18.6   Dynamically Binding Query Results   599

18.7   Retrieving Data from Multiple Tables with LINQ   602

18.8   Creating a Master/Detail View Application   608

18.9   Address Book Case Study   613

18.10 Tools and Web Resources   618

18.11 Wrap-Up   619

 

Chapter 19: Web App Development with ASP.NET          620

19.1   Introduction   621

19.2   Web Basics   622

19.3   Multitier Application Architecture   623

19.4   Your First Web Application   625

19.5   Standard Web Controls: Designing a Form   636

19.6   Validation Controls   641

19.7   Session Tracking   647

19.8   Case Study: Database-Driven ASP.NET Guestbook   657

19.9   Case Study: ASP.NET AJAX   664

19.10 Case Study: Password-Protected Books Database Application   664

19.11 Wrap-Up   664

 

Chapter 20: Searching and Sorting          666

20.1 Introduction   667

20.2 Searching Algorithms   667

20.3 Sorting Algorithms   677

20.4 Summary of the Efficiency of Searching and Sorting Algorithms   691

20.5 Wrap-Up   691

 

Chapter 21: Data Structures          692

21.1 Introduction   693

21.2 Simple-Type structs, Boxing and Unboxing   693

21.3 Self-Referential Classes   694

21.4 Linked Lists   695

21.5 Stacks   708

21.6 Queues   712

21.7 Trees   715

21.8 Wrap-Up   728

 

Chapter 22: Generics          730

22.1 Introduction   731

22.2 Motivation for Generic Methods   732

22.3 Generic-Method Implementation   734

22.4 Type Constraints   737

22.5 Overloading Generic Methods   739

22.6 Generic Classes   740

22.7 Wrap-Up   749

 

Chapter 23: Collections         751

23.1 Introduction   752

23.2 Collections Overview   752

23.3 Class Array and Enumerators   755

23.4 Nongeneric Collections   758

23.5 Generic Collections   770

23.6 Covariance and Contravariance for Generic Types   776

23.7 Wrap-Up   778

 

Chapter 24: GUI with Windows Presentation Foundation         780

24.1   Introduction   781

24.2   Windows Presentation Foundation (WPF)   781

24.3   XML Basics   783

24.4   Structuring Data   786

24.5   XML Namespaces   791

24.6   Declarative GUI Programming Using XAML   795

24.7   Creating a WPF Application in Visual C# Express   796

24.8   Laying Out Controls   798

24.9   Event Handling   804

24.10 Commands and Common Application Tasks   812

24.11 WPF GUI Customization   816

24.12 Using Styles to Change the Appearance of Controls   817

24.13 Customizing Windows   823

24.14 Defining a Control’s Appearance with Control Templates   826

24.15 Data-Driven GUIs with Data Binding   831

24.16 Wrap-Up   837

24.17 Web Resources   838

 

Chapter 25: WPF Graphics and Multimedia         839

25.1   Introduction   840

25.2   Controlling Fonts   840

25.3   Basic Shapes   842

25.4   Polygons and Polylines   843

25.5   Brushes   847

25.6   Transforms   853

25.7   WPF Customization: A Television GUI   855

25.8   Animations   864

25.9   (Optional) 3-D Objects and Transforms   867

25.10 Speech Synthesis and Speech Recognition   873

25.11 Wrap-Up   880

 

Chapter 26: XML and LINQ to XML         881

26.1   Introduction   882

26.2   Document Type Definitions (DTDs)   882

26.3   W3C XML Schema Documents   886

26.4   Extensible Stylesheet Language and XSL Transformations   893

26.5   LINQ to XML: Document Object Model (DOM)   902

26.6   LINQ to XML Class Hierarchy   906

26.7   LINQ to XML: Namespaces and Creating Documents   915

26.8   XSLT with Class XslCompiledTransform   918

26.9   Wrap-Up   920

26.10 Web Resources   920

 

Chapter 27: Web App Development with ASP.NET: A Deeper Look         921

27.1 Introduction   922

27.2 Case Study: Password-Protected Books Database Application   922

27.3 ASP.NET Ajax   940

27.4 Wrap-Up   947

 

Chapter 28: Web Services          948

28.1   Introduction   949

28.2   WCF Services Basics   950

28.3   Simple Object Access Protocol (SOAP)   950

28.4   Representational State Transfer (REST)  951

28.5   JavaScript Object Notation (JSON)   951

28.6   Publishing and Consuming SOAP-Based WCF Web Services   952

28.7   Publishing and Consuming REST-Based XML Web Services   960

28.8   Publishing and Consuming REST-Based JSON Web Services   964

28.9   Blackjack Web Service: Using Session Tracking in a SOAP-Based WCF Web Service   968

28.10 Airline Reservation Web Service: Database Access and Invoking a Service from ASP.NET   982

28.11 Equation Generator: Returning User-Defined Types   986

28.12 Wrap-Up   998

28.13 Deitel Web Services Resource Centers   999

 

Chapter 29: Silverlight and Rich Internet Applications       1000

29.1 Introduction   1001

29.2 Platform Overview   1001

29.3 Silverlight Runtime and Tools Installation   1002

29.4 Building a Silverlight WeatherViewer Application   1002

29.5 Animations and the FlickrViewer   1016

29.6 Images and Deep Zoom   1025

29.7 Audio and Video   1038

29.8 Wrap-Up   1043

 

Chapter 30: ATM Case Study, Part 1: Object-Oriented Design with the UML        1044

30.1 Introduction   1045

30.2 Examining the ATM Requirements Document   1045

30.3 Identifying the Classes in the ATM Requirements Document   1053

30.4 Identifying Class Attributes   1060

30.5 Identifying Objects’ States and Activities   1064

30.6 Identifying Class Operations   1068

30.7 Identifying Collaboration Among Objects   1075

30.8 Wrap-Up   1082

 

Chapter 31: ATM Case Study, Part 2: Implementing an Object-Oriented Design         1087

31.1 Introduction   1088

31.2 Starting to Program the Classes of the ATM System   1088

31.3 Incorporating Inheritance and Polymorphism into the ATM System   1093

31.4 ATM Case Study Implementation   1100

31.5 Wrap-Up   1124

 

Appendix A: Operator Precedence Chart         1127

 

Appendix B: Simple Types         1129

 

Appendix C: ASCII Character Set         1131

 

Appendix D: Number Systems          1132

D.1 Introduction   1133

D.2 Abbreviating Binary Numbers as Octal and Hexadecimal Numbers   1136

D.3 Converting Octal and Hexadecimal Numbers to Binary Numbers   1137

D.4 Converting from Binary, Octal or Hexadecimal to Decimal   1137

D.5 Converting from Decimal to Binary, Octal or Hexadecimal   1138

D.6 Negative Binary Numbers: Two’s Complement Notation   1140

 

Appendix E: UML 2: Additional Diagram Types         1142

E.1 Introduction   1142

E.2 Additional Diagram Types   1142

 

Appendix F: Unicode ®          1144

F.1 Introduction   1145

F.2 Unicode Transformation Formats   1146

F.3 Characters and Glyphs   1147

F.4 Advantages/Disadvantages of Unicode   1147

F.5 Using Unicode   1148

F.6 Character Ranges   1150

 

Appendix G: Using the Visual C# 2010 Debugger         1152

G.1 Introduction   1153

G.2 Breakpoints and the Continue Command   1153

G.3 DataTips and Visualizers   1159

G.4 The Locals and Watch Windows   1160

G.5 Controlling Execution Using the Step Into, Step Over, Step Out and Continue Commands   1163

G.6 Other Debugging Features   1166

 

Index 1170

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Rewards Program