contents · 1.8 c# 12 1.8.1 object-oriented programming 12 ... 1.13 visual studio express 2012...

12
Chapters 24–35 and Appendices D–G are PDF documents posted online at the book’s Companion Website (located at www.pearsonhighered.com/deitel/). Preface xix Before You Begin xxxv 1 Introduction to Computers, the Internet and Visual C# 1 1.1 Introduction 2 1.2 Hardware and Moore’s Law 2 1.3 Data Hierarchy 3 1.4 Computer Organization 6 1.5 Machine Languages, Assembly Languages and High-Level Languages 7 1.6 Object Technology 8 1.7 Internet and World Wide Web 10 1.8 C# 12 1.8.1 Object-Oriented Programming 12 1.8.2 Event-Driven Programming 12 1.8.3 Visual Programming 12 1.8.4 An International Standard; Other C# Implementations 12 1.8.5 Internet and Web Programming 13 1.8.6 Introducing async/await 13 1.8.7 Other Key Contemporary Programming Languages 13 1.9 Microsoft’s .NET 14 1.9.1 .NET Framework 14 1.9.2 Common Language Runtime 15 1.9.3 Platform Independence 15 1.9.4 Language Interoperability 15 1.10 Microsoft’s Windows ® Operating System 16 1.11 Windows Phone 8 for Smartphones 17 1.11.1 Selling Your Apps in the Windows Phone Marketplace 18 1.11.2 Free vs. Paid Apps 18 1.11.3 Testing Your Windows Phone Apps 18 1.12 Windows Azure™ and Cloud Computing 19 1.13 Visual Studio Express 2012 Integrated Development Environment 19 Contents cshtp5_PRINTONLYTOC.fm Page vii Wednesday, February 27, 2013 11:59 AM

Upload: doankien

Post on 26-Jun-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

Chapters 24–35 and Appendices D–G are PDF documents posted online at the book’sCompanion Website (located at www.pearsonhighered.com/deitel/).

Preface xix

Before You Begin xxxv

1 Introduction to Computers, the Internet and Visual C# 1

1.1 Introduction 21.2 Hardware and Moore’s Law 21.3 Data Hierarchy 31.4 Computer Organization 61.5 Machine Languages, Assembly Languages and High-Level Languages 71.6 Object Technology 81.7 Internet and World Wide Web 101.8 C# 12

1.8.1 Object-Oriented Programming 121.8.2 Event-Driven Programming 121.8.3 Visual Programming 121.8.4 An International Standard; Other C# Implementations 121.8.5 Internet and Web Programming 131.8.6 Introducing async/await 13

1.8.7 Other Key Contemporary Programming Languages 131.9 Microsoft’s .NET 14

1.9.1 .NET Framework 141.9.2 Common Language Runtime 151.9.3 Platform Independence 151.9.4 Language Interoperability 15

1.10 Microsoft’s Windows® Operating System 161.11 Windows Phone 8 for Smartphones 17

1.11.1 Selling Your Apps in the Windows Phone Marketplace 181.11.2 Free vs. Paid Apps 181.11.3 Testing Your Windows Phone Apps 18

1.12 Windows Azure™ and Cloud Computing 191.13 Visual Studio Express 2012 Integrated Development Environment 19

Contents

cshtp5_PRINTONLYTOC.fm Page vii Wednesday, February 27, 2013 11:59 AM

viii Contents

1.14 Painter Test-Drive in Visual Studio Express 2012 for Windows Desktop 191.15 Painter Test-Drive in Visual Studio Express 2012 for Windows 8 23

2 Dive Into® Visual Studio Express 2012 for Windows Desktop 33

2.1 Introduction 342.2 Overview of the Visual Studio Express 2012 IDE 342.3 Menu Bar and Toolbar 392.4 Navigating the Visual Studio IDE 41

2.4.1 Solution Explorer 432.4.2 Toolbox 442.4.3 Properties Window 44

2.5 Using Help 462.6 Using Visual App Development to Create a Simple App that Displays

Text and an Image 472.7 Wrap-Up 572.8 Web Resources 58

3 Introduction to C# Apps 653.1 Introduction 663.2 A Simple C# App: Displaying a Line of Text 663.3 Creating a Simple App in Visual Studio 723.4 Modifying Your Simple C# App 773.5 Formatting Text with Console.Write and Console.WriteLine 803.6 Another C# App: Adding Integers 813.7 Memory Concepts 853.8 Arithmetic 863.9 Decision Making: Equality and Relational Operators 903.10 Wrap-Up 94

4 Introduction to Classes, Objects, Methods and strings 106

4.1 Introduction 1074.2 Classes, Objects, Methods, Properties and Instance Variables 1074.3 Declaring a Class with a Method and Instantiating an Object of a Class 1084.4 Declaring a Method with a Parameter 1134.5 Instance Variables and Properties 1164.6 UML Class Diagram with a Property 1214.7 Software Engineering with Properties and set and get Accessors 1214.8 Auto-Implemented Properties 1234.9 Value Types vs. Reference Types 1234.10 Initializing Objects with Constructors 1254.11 Floating-Point Numbers and Type decimal 1284.12 Wrap-Up 134

cshtp5_PRINTONLYTOC.fm Page viii Wednesday, February 27, 2013 11:59 AM

Contents ix

5 Control Statements: Part 1 1425.1 Introduction 1435.2 Algorithms 1435.3 Pseudocode 1445.4 Control Structures 1445.5 if Single-Selection Statement 1465.6 if…else Double-Selection Statement 1485.7 while Repetition Statement 1525.8 Formulating Algorithms: Counter-Controlled Repetition 1545.9 Formulating Algorithms: Sentinel-Controlled Repetition 1585.10 Formulating Algorithms: Nested Control Statements 1665.11 Compound Assignment Operators 1715.12 Increment and Decrement Operators 1715.13 Simple Types 1745.14 Wrap-Up 175

6 Control Statements: Part 2 1896.1 Introduction 1906.2 Essentials of Counter-Controlled Repetition 1906.3 for Repetition Statement 1916.4 Examples Using the for Statement 1956.5 do…while Repetition Statement 1996.6 switch Multiple-Selection Statement 2016.7 break and continue Statements 2096.8 Logical Operators 2116.9 Structured-Programming Summary 2166.10 Wrap-Up 221

7 Methods: A Deeper Look 2317.1 Introduction 2327.2 Packaging Code in C# 2327.3 static Methods, static Variables and Class Math 2347.4 Declaring Methods with Multiple Parameters 2367.5 Notes on Declaring and Using Methods 2407.6 Method-Call Stack and Activation Records 2417.7 Argument Promotion and Casting 2427.8 The .NET Framework Class Library 2437.9 Case Study: Random-Number Generation 245

7.9.1 Scaling and Shifting Random Numbers 2497.9.2 Random-Number Repeatability for Testing and Debugging 250

7.10 Case Study: A Game of Chance; Introducing Enumerations 2507.11 Scope of Declarations 2557.12 Method Overloading 2587.13 Optional Parameters 260

cshtp5_PRINTONLYTOC.fm Page ix Wednesday, February 27, 2013 11:59 AM

x Contents

7.14 Named Parameters 2627.15 Recursion 2637.16 Passing Arguments: Pass-by-Value vs. Pass-by-Reference 2667.17 Wrap-Up 269

8 Arrays; Introduction to Exception Handling 2858.1 Introduction 2868.2 Arrays 2868.3 Declaring and Creating Arrays 2888.4 Examples Using Arrays 289

8.4.1 Creating and Initializing an Array 2898.4.2 Using an Array Initializer 2908.4.3 Calculating a Value to Store in Each Array Element 2918.4.4 Summing the Elements of an Array 2928.4.5 Using Bar Charts to Display Array Data Graphically 2938.4.6 Using the Elements of an Array as Counters 2958.4.7 Using Arrays to Analyze Survey Results; Introduction to

Exception Handling 2968.5 Case Study: Card Shuffling and Dealing Simulation 2998.6 foreach Statement 3038.7 Passing Arrays and Array Elements to Methods 3058.8 Passing Arrays by Value and by Reference 3078.9 Case Study: GradeBook Using an Array to Store Grades 3118.10 Multidimensional Arrays 3168.11 Case Study: GradeBook Using a Rectangular Array 3218.12 Variable-Length Argument Lists 3278.13 Using Command-Line Arguments 3298.14 Wrap-Up 331

9 Introduction to LINQ and the List Collection 3519.1 Introduction 3529.2 Querying an Array of int Values Using LINQ 3539.3 Querying an Array of Employee Objects Using LINQ 3579.4 Introduction to Collections 3629.5 Querying a Generic Collection Using LINQ 3659.6 Wrap-Up 3679.7 Deitel LINQ Resource Center 367

10 Classes and Objects: A Deeper Look 37110.1 Introduction 37210.2 Time Class Case Study 37210.3 Controlling Access to Members 37610.4 Referring to the Current Object’s Members with the this Reference 37710.5 Time Class Case Study: Overloaded Constructors 379

cshtp5_PRINTONLYTOC.fm Page x Wednesday, February 27, 2013 11:59 AM

Contents xi

10.6 Default and Parameterless Constructors 38510.7 Composition 38610.8 Garbage Collection and Destructors 38910.9 static Class Members 39010.10 readonly Instance Variables 39310.11 Data Abstraction and Encapsulation 39410.12 Class View and Object Browser 39610.13 Object Initializers 39810.14 Wrap-Up 398

11 Object-Oriented Programming: Inheritance 40511.1 Introduction 40611.2 Base Classes and Derived Classes 40711.3 protected Members 40911.4 Relationship between Base Classes and Derived Classes 410

11.4.1 Creating and Using a CommissionEmployee Class 41011.4.2 Creating a BasePlusCommissionEmployee Class without

Using Inheritance 41511.4.3 Creating a CommissionEmployee–BasePlusCommissionEmployee

Inheritance Hierarchy 42011.4.4 CommissionEmployee–BasePlusCommissionEmployee Inheritance

Hierarchy Using protected Instance Variables 42311.4.5 CommissionEmployee–BasePlusCommissionEmployee Inheritance

Hierarchy Using private Instance Variables 42811.5 Constructors in Derived Classes 43311.6 Software Engineering with Inheritance 43411.7 Class object 43411.8 Wrap-Up 435

12 OOP: Polymorphism, Interfaces and Operator Overloading 441

12.1 Introduction 44212.2 Polymorphism Examples 44412.3 Demonstrating Polymorphic Behavior 44512.4 Abstract Classes and Methods 44812.5 Case Study: Payroll System Using Polymorphism 450

12.5.1 Creating Abstract Base Class Employee 45112.5.2 Creating Concrete Derived Class SalariedEmployee 45312.5.3 Creating Concrete Derived Class HourlyEmployee 45512.5.4 Creating Concrete Derived Class CommissionEmployee 45712.5.5 Creating Indirect Concrete Derived Class

BasePlusCommissionEmployee 45812.5.6 Polymorphic Processing, Operator is and Downcasting 460

cshtp5_PRINTONLYTOC.fm Page xi Wednesday, February 27, 2013 11:59 AM

xii Contents

12.5.7 Summary of the Allowed Assignments Between Base-Class and Derived-Class Variables 465

12.6 sealed Methods and Classes 46612.7 Case Study: Creating and Using Interfaces 466

12.7.1 Developing an IPayable Hierarchy 46812.7.2 Declaring Interface IPayable 46912.7.3 Creating Class Invoice 46912.7.4 Modifying Class Employee to Implement Interface IPayable 47112.7.5 Modifying Class SalariedEmployee for Use with IPayable 47312.7.6 Using Interface IPayable to Process Invoices and Employees

Polymorphically 47412.7.7 Common Interfaces of the .NET Framework Class Library 476

12.8 Operator Overloading 47712.9 Wrap-Up 480

13 Exception Handling: A Deeper Look 48613.1 Introduction 48713.2 Example: Divide by Zero without Exception Handling 48813.3 Example: Handling DivideByZeroExceptions and FormatExceptions 491

13.3.1 Enclosing Code in a try Block 49313.3.2 Catching Exceptions 49313.3.3 Uncaught Exceptions 49413.3.4 Termination Model of Exception Handling 49513.3.5 Flow of Control When Exceptions Occur 495

13.4 .NET Exception Hierarchy 49613.4.1 Class SystemException 49613.4.2 Determining Which Exceptions a Method Throws 497

13.5 finally Block 49713.6 The using Statement 50413.7 Exception Properties 50513.8 User-Defined Exception Classes 50913.9 Wrap-Up 513

14 Graphical User Interfaces with Windows Forms: Part 1 518

14.1 Introduction 51914.2 Windows Forms 52014.3 Event Handling 522

14.3.1 A Simple Event-Driven GUI 52214.3.2 Auto-Generated GUI Code 52414.3.3 Delegates and the Event-Handling Mechanism 52614.3.4 Another Way to Create Event Handlers 52714.3.5 Locating Event Information 528

14.4 Control Properties and Layout 529

cshtp5_PRINTONLYTOC.fm Page xii Wednesday, February 27, 2013 11:59 AM

Contents xiii

14.5 Labels, TextBoxes and Buttons 53314.6 GroupBoxes and Panels 53614.7 CheckBoxes and RadioButtons 53914.8 PictureBoxes 54714.9 ToolTips 54914.10 NumericUpDown Control 55114.11 Mouse-Event Handling 55314.12 Keyboard-Event Handling 55614.13 Wrap-Up 559

15 Graphical User Interfaces with Windows Forms: Part 2 569

15.1 Introduction 57015.2 Menus 57015.3 MonthCalendar Control 57915.4 DateTimePicker Control 58015.5 LinkLabel Control 58315.6 ListBox Control 58715.7 CheckedListBox Control 59115.8 ComboBox Control 59415.9 TreeView Control 59815.10 ListView Control 60315.11 TabControl Control 60915.12 Multiple Document Interface (MDI) Windows 61415.13 Visual Inheritance 62115.14 User-Defined Controls 62615.15 Wrap-Up 630

16 Strings and Characters: A Deeper Look 63816.1 Introduction 63916.2 Fundamentals of Characters and Strings 64016.3 string Constructors 64116.4 string Indexer, Length Property and CopyTo Method 64216.5 Comparing strings 64316.6 Locating Characters and Substrings in strings 64616.7 Extracting Substrings from strings 64916.8 Concatenating strings 65016.9 Miscellaneous string Methods 65116.10 Class StringBuilder 65216.11 Length and Capacity Properties, EnsureCapacity Method and Indexer

of Class StringBuilder 65316.12 Append and AppendFormat Methods of Class StringBuilder 65516.13 Insert, Remove and Replace Methods of Class StringBuilder 65716.14 Char Methods 660

cshtp5_PRINTONLYTOC.fm Page xiii Wednesday, February 27, 2013 11:59 AM

xiv Contents

16.15 (Online) Introduction to Regular Expressions 66216.16 Wrap-Up 663

17 Files and Streams 66917.1 Introduction 67017.2 Data Hierarchy 67017.3 Files and Streams 67217.4 Classes File and Directory 67317.5 Creating a Sequential-Access Text File 68217.6 Reading Data from a Sequential-Access Text File 69117.7 Case Study: Credit Inquiry Program 69517.8 Serialization 70117.9 Creating a Sequential-Access File Using Object Serialization 70217.10 Reading and Deserializing Data from a Binary File 70617.11 Wrap-Up 708

18 Searching and Sorting 71518.1 Introduction 71618.2 Searching Algorithms 717

18.2.1 Linear Search 71718.2.2 Binary Search 721

18.3 Sorting Algorithms 72618.3.1 Selection Sort 72618.3.2 Insertion Sort 73018.3.3 Merge Sort 734

18.4 Summary of the Efficiency of Searching and Sorting Algorithms 74018.5 Wrap-Up 741

19 Data Structures 74619.1 Introduction 74719.2 Simple-Type structs, Boxing and Unboxing 74719.3 Self-Referential Classes 74819.4 Linked Lists 74919.5 Stacks 76219.6 Queues 76619.7 Trees 769

19.7.1 Binary Search Tree of Integer Values 77019.7.2 Binary Search Tree of IComparable Objects 777

19.8 Wrap-Up 782

20 Generics 78920.1 Introduction 79020.2 Motivation for Generic Methods 79120.3 Generic-Method Implementation 793

cshtp5_PRINTONLYTOC.fm Page xiv Wednesday, February 27, 2013 11:59 AM

Contents xv

20.4 Type Constraints 79620.5 Overloading Generic Methods 79820.6 Generic Classes 79920.7 Wrap-Up 808

21 Collections 81421.1 Introduction 81521.2 Collections Overview 81521.3 Class Array and Enumerators 81821.4 Nongeneric Collections 821

21.4.1 Class ArrayList 82121.4.2 Class Stack 82621.4.3 Class Hashtable 828

21.5 Generic Collections 83321.5.1 Generic Class SortedDictionary 83421.5.2 Generic Class LinkedList 836

21.6 Covariance and Contravariance for Generic Types 84021.7 Wrap-Up 843

22 Databases and LINQ 84922.1 Introduction 85022.2 Relational Databases 85122.3 A Books Database 85222.4 LINQ to Entities and the ADO.NET Entity Framework 85622.5 Querying a Database with LINQ 857

22.5.1 Creating the ADO.NET Entity Data Model Class Library 85822.5.2 Creating a Windows Forms Project and Configuring It to

Use the Entity Data Model 86222.5.3 Data Bindings Between Controls and the Entity Data Model 864

22.6 Dynamically Binding Query Results 86922.6.1 Creating the Display Query Results GUI 87022.6.2 Coding the Display Query Results App 871

22.7 Retrieving Data from Multiple Tables with LINQ 87422.8 Creating a Master/Detail View App 879

22.8.1 Creating the Master/Detail GUI 88022.8.2 Coding the Master/Detail App 881

22.9 Address Book Case Study 88322.9.1 Creating the Address Book App’s GUI 88422.9.2 Coding the Address Book App 885

22.10 Tools and Web Resources 88922.11 Wrap-Up 889

23 Web App Development with ASP.NET 89723.1 Introduction 898

cshtp5_PRINTONLYTOC.fm Page xv Wednesday, February 27, 2013 11:59 AM

xvi Contents

23.2 Web Basics 89923.3 Multitier App Architecture 90023.4 Your First Web App 902

23.4.1 Building the WebTime App 90423.4.2 Examining WebTime.aspx’s Code-Behind File 913

23.5 Standard Web Controls: Designing a Form 91423.6 Validation Controls 91823.7 Session Tracking 925

23.7.1 Cookies 92623.7.2 Session Tracking with HttpSessionState 92723.7.3 Options.aspx: Selecting a Programming Language 92823.7.4 Recommendations.aspx: Displaying Recommendations

Based on Session Values 93223.8 Case Study: Database-Driven ASP.NET Guestbook 933

23.8.1 Building a Web Form that Displays Data from a Database 93523.8.2 Modifying the Code-Behind File for the Guestbook App 940

23.9 Online Case Study: ASP.NET AJAX 94123.10 Online Case Study: Password-Protected Books Database App 94223.11 Wrap-Up 942

Chapters on the Web 949

A Operator Precedence Chart 950

B Simple Types 952

C ASCII Character Set 954

Appendices on the Web 955

Index 957

Chapters 24–35 and Appendices D–G are PDF documents posted online at the book’sCompanion Website (located at www.pearsonhighered.com/deitel/).

24 XML and LINQ to XML

25 Windows 8 UI and XAML

26 Windows 8 Graphics and Multimedia

cshtp5_PRINTONLYTOC.fm Page xvi Wednesday, February 27, 2013 11:59 AM

Contents xvii

27 Building a Windows Phone 8 App

28 Asynchronous Programming with async and await

29 Web App Development with ASP.NET: A Deeper Look

30 Web Services

31 Building a Windows Azure™ Cloud Computing App

32 GUI with Windows Presentation Foundation

33 WPF Graphics and Multimedia

34 ATM Case Study, Part 1: Object-Oriented Design with the UML

35 ATM Case Study, Part 2: Implementing an Object-Oriented Design

D Number Systems

E UML 2: Additional Diagram Types

F Unicode®

G Using the Visual C# 2012 Debugger

cshtp5_PRINTONLYTOC.fm Page xvii Wednesday, February 27, 2013 11:59 AM