C# 6 for Programmers, Sixth Edition

Book description

The professional programmer’s Deitel® guide to C# 6 and object-oriented development for Windows®

Written for programmers with a background in high-level language programming, C# 6 for Programmers applies the Deitel signature live-code approach to teaching programming and explores Microsoft’s C# 6 and .NET in depth. Concepts are presented in the context of 170+ fully coded and tested apps, complete with syntax shading, code highlighting, code walkthroughs, program outputs and hundreds of savvy software-development tips.

Start with an introduction to C# using an early classes and objects approach, then rapidly move on to more advanced topics, including LINQ, asynchronous programming with async and await and more. You’ll enjoy the treatment of object-oriented programming and an object-oriented design/UML® ATM case study, including a complete C# implementation. When you’ve mastered the book, you’ll be ready to start building industrial-strength, object-oriented C# apps.

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 textbooks, professional books, LiveLessons™ video products, e-books, resource centers and REVEL™ interactive multimedia courses with integrated labs and assessment to master major programming languages and platforms, including C#, C++, C, Java™, Android™ app development, iOS app development, Swift™, Visual Basic®, Python™ and Internet and web programming.

Features:

  • Use with Windows® 7, 8 or 10.

  • Integrated coverage of new C# 6 functionality: string interpolation, expression-bodied methods and properties, auto-implemented property initializers, getter-only properties, nameof, null-conditional operator, exception filters and more.

  • Entertaining and challenging code examples.

  • Deep treatment of classes, objects, inheritance, polymorphism and interfaces.

  • Generics, LINQ and generic collections; PLINQ (Parallel LINQ) for multicore performance.

  • Asynchronous programming with async and await; functional programming with lambdas, delegates and immutability.

  • Files; relational database with LINQ to Entities.

  • Object-oriented design ATM case study with full code implementation.

  • Emphasis on performance and software engineering principles.

  • Visit www.deitel.com

  • Download code examples

  • For Deitel’s programming training courses, www.deitel.com/training or write to deitel@deitel.com

  • Join the Deitel social networking communities:

  • Facebook® at facebook.com/DeitelFan

  • Twitter® at twitter.com/deitel

  • LinkedIn® at bit.ly/DeitelLinkedIn

  • YouTube™ at youtube.com/DeitelTV

  • Google+™ at google.com/+DeitelFan

  • Subscribe to the Deitel® Buzz e-mail newsletter at www.deitel.com/newsletter/subscribe.html

  • Table of contents

    1. About This E-Book
    2. Title Page
    3. Copyright Page
    4. Deitel® Series Page
      1. Deitel® Developer Series
      2. How To Program Series
      3. Simply Series
      4. VitalSource Web Books
      5. LiveLessons Video Learning Products
      6. REVEL™ Interactive Multimedia
    5. Dedication
    6. Contents
    7. Preface
      1. Contacting the Authors
      2. Join the Deitel & Associates, Inc. Social Media Communities
      3. New C# 6 Features
      4. A Tour of the Book
        1. Introduction to Visual C# and Visual Studio 2015 Community Edition
        2. Introduction to C# Fundamentals
        3. Object-Oriented Programming: A Deeper Look
        4. Windows Forms Graphical User Interfaces (GUIs)
        5. Strings and Files
        6. Generics and Generic Collections
        7. Functional Programming with LINQ, PLINQ, Lambdas, Delegates and Immutability
        8. Database with LINQ to Entities and SQL Server
        9. Asynchronous Programming
      5. Online Bonus Content
        1. Accessing the Bonus Content
        2. XML and LINQ to XML
        3. Windows Presentation Foundation (WPF) GUI, Graphics and Multimedia
        4. Case Study: Using the UML to Develop an Object-Oriented- Design and C# Implementation of the Software for an ATM (Automated Teller Machine)
      6. Future Online Bonus Content
        1. Universal Windows Platform (UWP) for Desktop and Mobile Apps
        2. REST Web Services
        3. Microsoft Azure™ Cloud Computing
      7. Notes About the Presentation
      8. Obtaining the Software Used in C# 6 for Programmers, 6/e
      9. Microsoft DreamSpark™
      10. Acknowledgments
      11. Reviewers
      12. About the Authors
      13. About Deitel & Associates, Inc.
    8. Before You Begin
      1. Font and Naming Conventions
      2. Visual Studio 2015 Community Edition
      3. Viewing File Extensions
      4. Obtaining the Source Code
      5. Configuring Visual Studio for Use with This Book
        1. Visual Studio Theme
        2. Line Numbers
        3. Tab Size for Code Indents
      6. If You’re Not Using Microsoft Visual C#...
        1. Mono Project
        2. .NET Core
    9. 1. Introduction
      1. 1.1 Introduction
      2. 1.2 Object Technology: A Brief Review
        1. The Automobile as an Object
        2. Methods and Classes
        3. Making Objects from Classes
        4. Reuse
        5. Messages and Method Calls
        6. Attributes and Instance Variables
        7. Properties, get Accessors and set Accessors
        8. Encapsulation
        9. Inheritance
        10. Object-Oriented Analysis and Design (OOAD)
        11. The UML (Unified Modeling Language)
      3. 1.3 C#
        1. 1.3.1 Object-Oriented Programming
        2. 1.3.2 Event-Driven Programming
        3. 1.3.3 Visual Programming
        4. 1.3.4 Generic and Functional Programming
        5. 1.3.5 An International Standard
        6. 1.3.6 C# on Non-Windows Platforms
        7. 1.3.7 Internet and Web Programming
        8. 1.3.8 Asynchronous Programming with async and await
      4. 1.4 Microsoft’s .NET
        1. 1.4.1 .NET Framework
        2. 1.4.2 Common Language Runtime
        3. 1.4.3 Platform Independence
        4. 1.4.4 Language Interoperability
      5. 1.5 Microsoft’s Windows® Operating System
      6. 1.6 Visual Studio Integrated Development Environment
      7. 1.7 Painter Test-Drive in Visual Studio Community
        1. Step 1: Checking Your Setup
        2. Step 2: Locating the Painter App’s Directory
        3. Step 3: Running the Painter App
        4. Step 4: Changing the Brush Color
        5. Step 5: Changing the Brush Color and Size
        6. Step 6: Finishing the Drawing
        7. Step 7: Stopping the App
    10. 2. Introduction to Visual Studio and Visual Programming
      1. 2.1 Introduction
      2. 2.2 Overview of the Visual Studio Community 2015 IDE
        1. 2.2.1 Introduction to Visual Studio Community 2015
        2. 2.2.2 Visual Studio Themes
        3. 2.2.3 Links on the Start Page
        4. 2.2.4 Creating a New Project
        5. 2.2.5 New Project Dialog and Project Templates
        6. 2.2.6 Forms and Controls
      3. 2.3 Menu Bar and Toolbar
      4. 2.4 Navigating the Visual Studio IDE
        1. 2.4.1 Solution Explorer
        2. 2.4.2 Toolbox
        3. 2.4.3 Properties Window
      5. 2.5 Help Menu and Context-Sensitive Help
      6. 2.6 Visual Programming: Creating a Simple App that Displays Text and an Image
        1. Step 1: Closing the Open Project
        2. Step 2: Creating the New Project
        3. Step 11: Inserting an Image
        4. Step 12: Saving the Project
        5. Step 13: Running the Project
      7. 2.7 Wrap-Up
      8. 2.8 Web Resources
    11. 3. Introduction to C# App Programming
      1. 3.1 Introduction
      2. 3.2 Simple App: Displaying a Line of Text
        1. 3.2.1 Comments
        2. 3.2.2 using Directive
        3. 3.2.3 Blank Lines and Whitespace
        4. 3.2.4 Class Declaration
        5. 3.2.5 Main Method
        6. 3.2.6 Displaying a Line of Text
        7. 3.2.7 Matching Left ({) and Right (}) Braces
      3. 3.3 Creating a Simple App in Visual Studio
        1. 3.3.1 Creating the Console App
        2. 3.3.2 Changing the Name of the App File
        3. 3.3.3 Writing Code and Using IntelliSense
        4. 3.3.4 Compiling and Running the App
        5. 3.3.5 Errors, Error Messages and the Error List Window
      4. 3.4 Modifying Your Simple C# App
        1. 3.4.1 Displaying a Single Line of Text with Multiple Statements
        2. 3.4.2 Displaying Multiple Lines of Text with a Single Statement
      5. 3.5 String Interpolation
      6. 3.6 Another C# App: Adding Integers
        1. 3.6.1 Declaring the int Variable number1
        2. 3.6.2 Declaring Variables number2 and sum
        3. 3.6.3 Prompting the User for Input
        4. 3.6.4 Reading a Value into Variable number1
        5. 3.6.5 Prompting the User for Input and Reading a Value into number2
        6. 3.6.6 Summing number1 and number2
        7. 3.6.7 Displaying the sum with string Interpolation
        8. 3.6.8 Performing Calculations in Output Statements
      7. 3.7 Arithmetic
        1. 3.7.1 Arithmetic Expressions in Straight-Line Form
        2. 3.7.2 Parentheses for Grouping Subexpressions
        3. 3.7.3 Rules of Operator Precedence
      8. 3.8 Decision Making: Equality and Relational Operators
      9. 3.9 Wrap-Up
    12. 4. Introduction to Classes, Objects, Methods and strings
      1. 4.1 Introduction
      2. 4.2 Test-Driving an Account Class
        1. 4.2.1 Instantiating an Object—Keyword new
        2. 4.2.2 Calling Class Account’s GetName Method
        3. 4.2.3 Inputting a Name from the User
        4. 4.2.4 Calling Class Account’s SetName Method
      3. 4.3 Account Class with an Instance Variable and Set and Get Methods
        1. 4.3.1 Account Class Declaration
        2. 4.3.2 Keyword class and the Class Body
        3. 4.3.3 Instance Variable name of Type string
        4. 4.3.4 SetName Method
        5. 4.3.5 GetName Method
        6. 4.3.6 Access Modifiers private and public
        7. 4.3.7 Account UML Class Diagram
      4. 4.4 Creating, Compiling and Running a Visual C# Project with Two Classes
      5. 4.5 Software Engineering with Set and Get Methods
      6. 4.6 Account Class with a Property Rather Than Set and Get Methods
        1. 4.6.1 Class AccountTest Using Account’s Name Property
        2. 4.6.2 Account Class with an Instance Variable and a Property
        3. 4.6.3 Account UML Class Diagram with a Property
      7. 4.7 Auto-Implemented Properties
      8. 4.8 Account Class: Initializing Objects with Constructors
        1. 4.8.1 Declaring an Account Constructor for Custom Object Initialization
        2. 4.8.2 Class AccountTest: Initializing Account Objects When They’re Created
      9. 4.9 Account Class with a Balance; Processing Monetary Amounts
        1. 4.9.1 Account Class with a decimal balance Instance Variable
        2. 4.9.2 AccountTest Class That Uses Account Objects with Balances
      10. 4.10 Wrap-Up
    13. 5. Control Statements: Part 1
      1. 5.1 Introduction
      2. 5.2 Control Structures
        1. 5.2.1 Sequence Structure
        2. 5.2.2 Selection Statements
        3. 5.2.3 Iteration Statements
        4. 5.2.4 Summary of Control Statements
      3. 5.3 if Single-Selection Statement
      4. 5.4 if...else Double-Selection Statement
        1. 5.4.1 Nested if...else Statements
        2. 5.4.2 Dangling-else Problem
        3. 5.4.3 Blocks
        4. 5.4.4 Conditional Operator (?:)
      5. 5.5 Student Class: Nested if...else Statements
      6. 5.6 while Iteration Statement
      7. 5.7 Counter-Controlled Iteration
        1. 5.7.1 Implementing Counter-Controlled Iteration
        2. 5.7.2 Integer Division and Truncation
      8. 5.8 Sentinel-Controlled Iteration
        1. 5.8.1 Implementing Sentinel-Controlled Iteration
        2. 5.8.2 Program Logic for Sentinel-Controlled Iteration
        3. 5.8.3 Braces in a while Statement
        4. 5.8.4 Converting Between Simple Types Explicitly and Implicitly
        5. 5.8.5 Formatting Floating-Point Numbers
      9. 5.9 Nested Control Statements
      10. 5.10 Compound Assignment Operators
      11. 5.11 Increment and Decrement Operators
        1. 5.11.1 Prefix Increment vs. Postfix Increment
        2. 5.11.2 Simplifying Increment Statements
        3. 5.11.3 Operator Precedence and Associativity
      12. 5.12 Simple Types
      13. 5.13 Wrap-Up
    14. 6. Control Statements: Part 2
      1. 6.1 Introduction
      2. 6.2 Essentials of Counter-Controlled Iteration
      3. 6.3 for Iteration Statement
        1. 6.3.1 A Closer Look at the for Statement’s Header
        2. 6.3.2 General Format of a for Statement
        3. 6.3.3 Scope of a for Statement’s Control Variable
        4. 6.3.4 Expressions in a for Statement’s Header Are Optional
        5. 6.3.5 UML Activity Diagram for the for Statement
      4. 6.4 App: Summing Even Integers
      5. 6.5 App: Compound-Interest Calculations
        1. 6.5.1 Performing the Interest Calculations with Math Method pow
        2. 6.5.2 Formatting with Field Widths and Alignment
        3. 6.5.3 Caution: Do Not Use float or double for Monetary Amounts
      6. 6.6 do...while Iteration Statement
      7. 6.7 switch Multiple-Selection Statement
        1. 6.7.1 Using a switch Statement to Count A, B, C, D and F Grades
        2. 6.7.2 switch Statement UML Activity Diagram
        3. 6.7.3 Notes on the Expression in Each case of a switch
      8. 6.8 Class AutoPolicy Case Study: strings in switch Statements
      9. 6.9 break and continue Statements
        1. 6.9.1 break Statement
        2. 6.9.2 continue Statement
      10. 6.10 Logical Operators
        1. 6.10.1 Conditional AND (&&) Operator
        2. 6.10.2 Conditional OR (||) Operator
        3. 6.10.3 Short-Circuit Evaluation of Complex Conditions
        4. 6.10.4 Boolean Logical AND (&) and Boolean Logical OR (|) Operators
        5. 6.10.5 Boolean Logical Exclusive OR (^)
        6. 6.10.6 Logical Negation (!) Operator
        7. 6.10.7 Logical Operators Example
      11. 6.11 Wrap-Up
    15. 7. Methods: A Deeper Look
      1. 7.1 Introduction
      2. 7.2 Packaging Code in C#
      3. 7.3 static Methods, static Variables and Class Math
        1. 7.3.1 Math Class Methods
        2. 7.3.2 Math Class Constants PI and E
        3. 7.3.3 Why Is Main Declared static?
        4. 7.3.4 Additional Comments About Main
      4. 7.4 Methods with Multiple Parameters
        1. 7.4.1 Keyword static
        2. 7.4.2 Method Maximum
        3. 7.4.3 Assembling strings with Concatenation
        4. 7.4.4 Breaking Apart Large string Literals
        5. 7.4.5 When to Declare Variables as Fields
        6. 7.4.6 Implementing Method Maximum by Reusing Method Math.Max
      5. 7.5 Notes on Using Methods
      6. 7.6 Argument Promotion and Casting
        1. 7.6.1 Promotion Rules
        2. 7.6.2 Sometimes Explicit Casts Are Required
      7. 7.7 The .NET Framework Class Library
      8. 7.8 Case Study: Random-Number Generation
        1. 7.8.1 Creating an Object of Type Random
        2. 7.8.2 Generating a Random Integer
        3. 7.8.3 Scaling the Random-Number Range
        4. 7.8.4 Shifting Random-Number Range
        5. 7.8.5 Combining Shifting and Scaling
        6. 7.8.6 Rolling a Six-Sided Die
        7. 7.8.7 Scaling and Shifting Random Numbers
        8. 7.8.8 Repeatability for Testing and Debugging
      9. 7.9 Case Study: A Game of Chance; Introducing Enumerations
        1. 7.9.1 Method RollDice
        2. 7.9.2 Method Main’s Local Variables
        3. 7.9.3 enum Type Status
        4. 7.9.4 The First Roll
        5. 7.9.5 enum Type DiceNames
        6. 7.9.6 Underlying Type of an enum
        7. 7.9.7 Comparing Integers and enum Constants
      10. 7.10 Scope of Declarations
      11. 7.11 Method-Call Stack and Activation Records
        1. 7.11.1 Method-Call Stack
        2. 7.11.2 Stack Frames
        3. 7.11.3 Local Variables and Stack Frames
        4. 7.11.4 Stack Overflow
        5. 7.11.5 Method-Call Stack in Action
      12. 7.12 Method Overloading
        1. 7.12.1 Declaring Overloaded Methods
        2. 7.12.2 Distinguishing Between Overloaded Methods
        3. 7.12.3 Return Types of Overloaded Methods
      13. 7.13 Optional Parameters
      14. 7.14 Named Parameters
      15. 7.15 C# 6 Expression-Bodied Methods and Properties
      16. 7.16 Recursion
        1. 7.16.1 Base Cases and Recursive Calls
        2. 7.16.2 Recursive Factorial Calculations
        3. 7.16.3 Implementing Factorial Recursively
      17. 7.17 Value Types vs. Reference Types
      18. 7.18 Passing Arguments By Value and By Reference
        1. 7.18.1 ref and out Parameters
        2. 7.18.2 Demonstrating ref, out and Value Parameters
      19. 7.19 Wrap-Up
    16. 8. Arrays; Introduction to Exception Handling
      1. 8.1 Introduction
      2. 8.2 Arrays
      3. 8.3 Declaring and Creating Arrays
      4. 8.4 Examples Using Arrays
        1. 8.4.1 Creating and Initializing an Array
        2. 8.4.2 Using an Array Initializer
        3. 8.4.3 Calculating a Value to Store in Each Array Element
        4. 8.4.4 Summing the Elements of an Array
        5. 8.4.5 Iterating Through Arrays with foreach
        6. 8.4.6 Using Bar Charts to Display Array Data Graphically; Introducing Type Inference with var
        7. 8.4.7 Using the Elements of an Array as Counters
      5. 8.5 Using Arrays to Analyze Survey Results; Intro to Exception Handling
        1. 8.5.1 Summarizing the Results
        2. 8.5.2 Exception Handling: Processing the Incorrect Response
        3. 8.5.3 The try Statement
        4. 8.5.4 Executing the catch Block
        5. 8.5.5 Message Property of the Exception Parameter
      6. 8.6 Case Study: Card Shuffling and Dealing Simulation
        1. 8.6.1 Class Card and Getter-Only Auto-Implemented Properties
        2. 8.6.2 Class DeckOfCards
        3. 8.6.3 Shuffling and Dealing Cards
      7. 8.7 Passing Arrays and Array Elements to Methods
      8. 8.8 Case Study: GradeBook Using an Array to Store Grades
      9. 8.9 Multidimensional Arrays
        1. 8.9.1 Rectangular Arrays
        2. 8.9.2 Jagged Arrays
        3. 8.9.3 Two-Dimensional Array Example: Displaying Element Values
      10. 8.10 Case Study: GradeBook Using a Rectangular Array
      11. 8.11 Variable-Length Argument Lists
      12. 8.12 Using Command-Line Arguments
      13. 8.13 (Optional) Passing Arrays by Value and by Reference
      14. 8.14 Wrap-Up
    17. 9. Introduction to LINQ and the List Collection
      1. 9.1 Introduction
      2. 9.2 Querying an Array of int Values Using LINQ
        1. 9.2.1 The from Clause
        2. 9.2.2 The where Clause
        3. 9.2.3 The select Clause
        4. 9.2.4 Iterating Through the Results of the LINQ Query
        5. 9.2.5 The orderby Clause
        6. 9.2.6 Interface IEnumerable<T>
      3. 9.3 Querying an Array of Employee Objects Using LINQ
        1. 9.3.1 Accessing the Properties of a LINQ Query’s Range Variable
        2. 9.3.2 Sorting a LINQ Query’s Results by Multiple Properties
        3. 9.3.3 Any, First and Count Extension Methods
        4. 9.3.4 Selecting a Property of an Object
        5. 9.3.5 Creating New Types in the select Clause of a LINQ Query
      4. 9.4 Introduction to Collections
        1. 9.4.1 List<T> Collection
        2. 9.4.2 Dynamically Resizing a List<T> Collection
      5. 9.5 Querying the Generic List Collection Using LINQ
        1. 9.5.1 The let Clause
        2. 9.5.2 Deferred Execution
        3. 9.5.3 Extension Methods ToArray and ToList
        4. 9.5.4 Collection Initializers
      6. 9.6 Wrap-Up
      7. 9.7 Deitel LINQ Resource Center
    18. 10. Classes and Objects: A Deeper Look
      1. 10.1 Introduction
      2. 10.2 Time Class Case Study; Throwing Exceptions
        1. 10.2.1 Time1 Class Declaration
        2. 10.2.2 Using Class Time1
      3. 10.3 Controlling Access to Members
      4. 10.4 Referring to the Current Object’s Members with the this Reference
      5. 10.5 Time Class Case Study: Overloaded Constructors
        1. 10.5.1 Class Time2 with Overloaded Constructors
        2. 10.5.2 Using Class Time2’s Overloaded Constructors
      6. 10.6 Default and Parameterless Constructors
      7. 10.7 Composition
        1. 10.7.1 Class Date
        2. 10.7.2 Class Employee
        3. 10.7.3 Class EmployeeTest
      8. 10.8 Garbage Collection and Destructors
      9. 10.9 static Class Members
      10. 10.10 readonly Instance Variables
      11. 10.11 Class View and Object Browser
        1. 10.11.1 Using the Class View Window
        2. 10.11.2 Using the Object Browser
      12. 10.12 Object Initializers
      13. 10.13 Operator Overloading; Introducing struct
        1. 10.13.1 Creating Value Types with struct
        2. 10.13.2 Value Type ComplexNumber
        3. 10.13.3 Class ComplexTest
      14. 10.14 Time Class Case Study: Extension Methods
      15. 10.15 Wrap-Up
    19. 11. Object-Oriented Programming: Inheritance
      1. 11.1 Introduction
      2. 11.2 Base Classes and Derived Classes
      3. 11.3 protected Members
      4. 11.4 Relationship between Base Classes and Derived Classes
        1. 11.4.1 Creating and Using a CommissionEmployee Class
        2. 11.4.2 Creating a BasePlusCommissionEmployee Class without Using Inheritance
        3. 11.4.3 Creating a CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy
        4. 11.4.4 CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using protected Instance Variables
        5. 11.4.5 CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using private Instance Variables
      5. 11.5 Constructors in Derived Classes
      6. 11.6 Software Engineering with Inheritance
      7. 11.7 Class object
      8. 11.8 Wrap-Up
    20. 12. OOP: Polymorphism and Interfaces
      1. 12.1 Introduction
      2. 12.2 Polymorphism Examples
      3. 12.3 Demonstrating Polymorphic Behavior
      4. 12.4 Abstract Classes and Methods
      5. 12.5 Case Study: Payroll System Using Polymorphism
        1. 12.5.1 Creating Abstract Base Class Employee
        2. 12.5.2 Creating Concrete Derived Class SalariedEmployee
        3. 12.5.3 Creating Concrete Derived Class HourlyEmployee
        4. 12.5.4 Creating Concrete Derived Class CommissionEmployee
        5. 12.5.5 Creating Indirect Concrete Derived Class BasePlusCommissionEmployee
        6. 12.5.6 Polymorphic Processing, Operator is and Downcasting
        7. 12.5.7 Summary of the Allowed Assignments Between Base-Class and Derived-Class Variables
      6. 12.6 sealed Methods and Classes
      7. 12.7 Case Study: Creating and Using Interfaces
        1. 12.7.1 Developing an IPayable Hierarchy
        2. 12.7.2 Declaring Interface IPayable
        3. 12.7.3 Creating Class Invoice
        4. 12.7.4 Modifying Class Employee to Implement Interface IPayable
        5. 12.7.5 Using Interface IPayable to Process Invoices and Employees Polymorphically
        6. 12.7.6 Common Interfaces of the .NET Framework Class Library
      8. 12.8 Wrap-Up
    21. 13. Exception Handling: A Deeper Look
      1. 13.1 Introduction
      2. 13.2 Example: Divide by Zero without Exception Handling
        1. 13.2.1 Dividing By Zero
        2. 13.2.2 Enter a Non-Numeric Denominator
        3. 13.2.3 Unhandled Exceptions Terminate the App
      3. 13.3 Example: Handling DivideByZeroExceptions and FormatExceptions
        1. 13.3.1 Enclosing Code in a try Block
        2. 13.3.2 Catching Exceptions
        3. 13.3.3 Uncaught Exceptions
        4. 13.3.4 Termination Model of Exception Handling
        5. 13.3.5 Flow of Control When Exceptions Occur
      4. 13.4 .NET Exception Hierarchy
        1. 13.4.1 Class SystemException
        2. 13.4.2 Which Exceptions Might a Method Throw?
      5. 13.5 finally Block
        1. 13.5.1 Moving Resource-Release Code to a finally Block
        2. 13.5.2 Demonstrating the finally Block
        3. 13.5.3 Throwing Exceptions Using the throw Statement
        4. 13.5.4 Rethrowing Exceptions
        5. 13.5.5 Returning After a finally Block
      6. 13.6 The using Statement
      7. 13.7 Exception Properties
        1. 13.7.1 Property InnerException
        2. 13.7.2 Other Exception Properties
        3. 13.7.3 Demonstrating Exception Properties and Stack Unwinding
        4. 13.7.4 Throwing an Exception with an InnerException
        5. 13.7.5 Displaying Information About the Exception
      8. 13.8 User-Defined Exception Classes
      9. 13.9 Checking for null References; Introducing C# 6’s ?. Operator
        1. 13.9.1 Null-Conditional Operator (?.)
        2. 13.9.2 Revisiting Operators is and as
        3. 13.9.3 Nullable Types
        4. 13.9.4 Null Coalescing Operator (??)
      10. 13.10 Exception Filters and the C# 6 when Clause
      11. 13.11 Wrap-Up
    22. 14. Graphical User Interfaces with Windows Forms: Part 1
      1. 14.1 Introduction
      2. 14.2 Windows Forms
      3. 14.3 Event Handling
        1. 14.3.1 A Simple Event-Driven GUI
        2. 14.3.2 Auto-Generated GUI Code
        3. 14.3.3 Delegates and the Event-Handling Mechanism
        4. 14.3.4 Another Way to Create Event Handlers
        5. 14.3.5 Locating Event Information
      4. 14.4 Control Properties and Layout
        1. 14.4.1 Anchoring and Docking
        2. 14.4.2 Using Visual Studio To Edit a GUI’s Layout
      5. 14.5 Labels, TextBoxes and Buttons
      6. 14.6 GroupBoxes and Panels
      7. 14.7 CheckBoxes and RadioButtons
        1. 14.7.1 CheckBoxes
        2. 14.7.2 Combining Font Styles with Bitwise Operators
        3. 14.7.3 RadioButtons
      8. 14.8 PictureBoxes
      9. 14.9 ToolTips
      10. 14.10 NumericUpDown Control
      11. 14.11 Mouse-Event Handling
      12. 14.12 Keyboard-Event Handling
      13. 14.13 Wrap-Up
    23. 15. Graphical User Interfaces with Windows Forms: Part 2
      1. 15.1 Introduction
      2. 15.2 Menus
      3. 15.3 MonthCalendar Control
      4. 15.4 DateTimePicker Control
      5. 15.5 LinkLabel Control
      6. 15.6 ListBox Control
      7. 15.7 CheckedListBox Control
      8. 15.8 ComboBox Control
      9. 15.9 TreeView Control
      10. 15.10 ListView Control
      11. 15.11 TabControl Control
      12. 15.12 Multiple Document Interface (MDI) Windows
      13. 15.13 Visual Inheritance
      14. 15.14 User-Defined Controls
      15. 15.15 Wrap-Up
    24. 16. Strings and Characters: A Deeper Look
      1. 16.1 Introduction
      2. 16.2 Fundamentals of Characters and Strings
      3. 16.3 string Constructors
      4. 16.4 string Indexer, Length Property and CopyTo Method
      5. 16.5 Comparing strings
      6. 16.6 Locating Characters and Substrings in strings
      7. 16.7 Extracting Substrings from strings
      8. 16.8 Concatenating strings
      9. 16.9 Miscellaneous string Methods
      10. 16.10 Class StringBuilder
      11. 16.11 Length and Capacity Properties, EnsureCapacity Method and Indexer of Class StringBuilder
      12. 16.12 Append and AppendFormat Methods of Class StringBuilder
      13. 16.13 Insert, Remove and Replace Methods of Class StringBuilder
      14. 16.14 Char Methods
      15. 16.15 Introduction to Regular Expressions (Online)
      16. 16.16 Wrap-Up
    25. 17. Files and Streams
      1. 17.1 Introduction
      2. 17.2 Files and Streams
      3. 17.3 Creating a Sequential-Access Text File
      4. 17.4 Reading Data from a Sequential-Access Text File
      5. 17.5 Case Study: Credit-Inquiry Program
      6. 17.6 Serialization
      7. 17.7 Creating a Sequential-Access File Using Object Serialization
      8. 17.8 Reading and Deserializing Data from a Binary File
      9. 17.9 Classes File and Directory
        1. 17.9.1 Demonstrating Classes File and Directory
        2. 17.9.2 Searching Directories with LINQ
      10. 17.10 Wrap-Up
    26. 18. Generics
      1. 18.1 Introduction
      2. 18.2 Motivation for Generic Methods
      3. 18.3 Generic-Method Implementation
      4. 18.4 Type Constraints
        1. 18.4.1 IComparable<T> Interface
        2. 18.4.2 Specifying Type Constraints
      5. 18.5 Overloading Generic Methods
      6. 18.6 Generic Classes
      7. 18.7 Wrap-Up
    27. 19. Generic Collections; Functional Programming with LINQ/PLINQ
      1. 19.1 Introduction
      2. 19.2 Collections Overview
      3. 19.3 Class Array and Enumerators
        1. 19.3.1 C# 6 using static Directive
        2. 19.3.2 Class UsingArray’s static Fields
        3. 19.3.3 Array Method Sort
        4. 19.3.4 Array Method Copy
        5. 19.3.5 Array Method BinarySearch
        6. 19.3.6 Array Method GetEnumerator and Interface IEnumerator
        7. 19.3.7 Iterating Over a Collection with foreach
        8. 19.3.8 Array Methods Clear, IndexOf, LastIndexOf and Reverse
      4. 19.4 Dictionary Collections
        1. 19.4.1 Dictionary Fundamentals
        2. 19.4.2 Using the SortedDictionary Collection
      5. 19.5 Generic LinkedList Collection
      6. 19.6 C# 6 Null Conditional Operator ?[]
      7. 19.7 C# 6 Dictionary Initializers and Collection Initializers
      8. 19.8 Delegates
        1. 19.8.1 Declaring a Delegate Type
        2. 19.8.2 Declaring a Delegate Variable
        3. 19.8.3 Delegate Parameters
        4. 19.8.4 Passing a Method Name Directly to a Delegate Parameter
      9. 19.9 Lambda Expressions
        1. 19.9.1 Expression Lambdas
        2. 19.9.2 Assigning Lambdas to Delegate Variables
        3. 19.9.3 Explicitly Typed Lambda Parameters
        4. 19.9.4 Statement Lambdas
      10. 19.10 Introduction to Functional Programming
      11. 19.11 Functional Programming with LINQ Method-Call Syntax and Lambdas
        1. 19.11.1 LINQ Extension Methods Min, Max, Sum and Average
        2. 19.11.2 Aggregate Extension Method for Reduction Operations
        3. 19.11.3 The Where Extension Method for Filtering Operations
        4. 19.11.4 Select Extension Method for Mapping Operations
      12. 19.12 PLINQ: Improving LINQ to Objects Performance with Multicore
      13. 19.13 (Optional) Covariance and Contravariance for Generic Types
      14. 19.14 Wrap-Up
    28. 20. Databases and LINQ
      1. 20.1 Introduction
      2. 20.2 Relational Databases
      3. 20.3 A Books Database
      4. 20.4 LINQ to Entities and the ADO.NET Entity Framework
      5. 20.5 Querying a Database with LINQ
        1. 20.5.1 Creating the ADO.NET Entity Data Model Class Library
        2. 20.5.2 Creating a Windows Forms Project and Configuring It to Use the Entity Data Model
        3. 20.5.3 Data Bindings Between Controls and the Entity Data Model
      6. 20.6 Dynamically Binding Query Results
        1. 20.6.1 Creating the Display Query Results GUI
        2. 20.6.2 Coding the Display Query Results App
      7. 20.7 Retrieving Data from Multiple Tables with LINQ
      8. 20.8 Creating a Master/Detail View App
        1. 20.8.1 Creating the Master/Detail GUI
        2. 20.8.2 Coding the Master/Detail App
      9. 20.9 Address Book Case Study
        1. 20.9.1 Creating the Address Book App’s GUI
        2. 20.9.2 Coding the Address Book App
      10. 20.10 Tools and Web Resources
      11. 20.11 Wrap-Up
    29. 21. Asynchronous Programming with async and await
      1. 21.1 Introduction
      2. 21.2 Basics of async and await
        1. 21.2.1 async Modifier
        2. 21.2.2 await Expression
        3. 21.2.3 async, await and Threads
      3. 21.3 Executing an Asynchronous Task from a GUI App
        1. 21.3.1 Performing a Task Asynchronously
        2. 21.3.2 Method calculateButton_Click
        3. 21.3.3 Task Method Run: Executing Asynchronously in a Separate Thread
        4. 21.3.4 awaiting the Result
        5. 21.3.5 Calculating the Next Fibonacci Value Synchronously
      4. 21.4 Sequential Execution of Two Compute-Intensive Tasks
      5. 21.5 Asynchronous Execution of Two Compute-Intensive Tasks
        1. 21.5.1 awaiting Multiple Tasks with Task Method WhenAll
        2. 21.5.2 Method StartFibonacci
        3. 21.5.3 Modifying a GUI from a Separate Thread
        4. 21.5.4 awaiting One of Several Tasks with Task Method WhenAny
      6. 21.6 Invoking a Flickr Web Service Asynchronously with HttpClient
        1. 21.6.1 Using Class HttpClient to Invoke a Web Service
        2. 21.6.2 Invoking the Flickr Web Service’s flickr.photos.search Method
        3. 21.6.3 Processing the XML Response
        4. 21.6.4 Binding the Photo Titles to the ListBox
        5. 21.6.5 Asynchronously Downloading an Image’s Bytes
      7. 21.7 Displaying an Asynchronous Task’s Progress
      8. 21.8 Wrap-Up
    30. 22. XML and LINQ to XML
      1. 22.1 Introduction
      2. 22.2 XML Basics
        1. Viewing and Modifying XML Documents
        2. Processing XML Documents
        3. Validating XML Documents
        4. Formatting and Manipulating XML Documents
      3. 22.3 Structuring Data
        1. Viewing an XML Document in Microsoft Edge
        2. XML Markup for a Business Letter
      4. 22.4 XML Namespaces
        1. Differentiating Elements with Namespaces
        2. Specifying a Default Namespace
        3. Namespaces in XML Vocabularies
      5. 22.5 Document Type Definitions (DTDs)
        1. Creating a Document Type Definition
        2. Defining Elements in a DTD
        3. Defining Attributes in a DTD
        4. Character Data vs. Parsed Character Data
        5. Defining Empty Elements in a DTD
        6. Well-Formed Documents vs. Valid Documents
      6. 22.6 W3C XML Schema Documents
        1. Validating Against an XML Schema Document
        2. Creating an XML Schema Document
        3. Defining an Element in XML Schema
        4. A Closer Look at Types in XML Schema
        5. XML Schema with Simple and Complext Types
        6. Opening schema Tag
        7. simpleType Element gigahertz
        8. complexType Element CPU
        9. complexType Element portable
        10. Using the laptop Element
        11. Automatically Creating Schemas using Visual Studio
      7. 22.7 Extensible Stylesheet Language and XSL Transformations
        1. A Simple XSL Example
        2. XSL for Transforming sports.xml
        3. stylesheet Start Tag
        4. xsl:output Element
        5. xsl:template Element
        6. xsl:for-each Element
        7. Using XSLT to Sort and Format Data
        8. Summary of XSL Style-Sheet Elements
      8. 22.8 LINQ to XML: Document Object Model (DOM)
        1. Reading an XML Document with an XDocument
      9. 22.9 LINQ to XML Class Hierarchy
        1. locateComboBox_SelectedIndexChanged Event Handler
        2. PrintIDs Method
        3. LINQ to XML Class Hierarchy
        4. firstChildButton_Click Event Handler
        5. NodeText Method
        6. Other Button Event Handlers
      10. 22.10 LINQ to XML: Namespaces and Creating Documents
      11. 22.11 XSLT with Class XslCompiledTransform
        1. Performing an XSL Transformation in C# Using the .NET Framework
      12. 22.12 Wrap-Up
    31. 23. GUI with Windows Presentation Foundation
      1. 23.1 Introduction
      2. 23.2 Windows Presentation Foundation (WPF)
      3. 23.3 Declarative GUI Programming Using XAML
      4. 23.4 Creating a WPF App
      5. 23.5 Laying Out Controls
        1. 23.5.1 General Layout Principles
        2. 23.5.2 Layout in Action
      6. 23.6 Event Handling
      7. 23.7 Commands and Common Application Tasks
      8. 23.8 WPF GUI Customization
      9. 23.9 Using Styles to Change the Appearance of Controls
      10. 23.10 Customizing Windows
      11. 23.11 Defining a Control’s Appearance with Control Templates
      12. 23.12 Data-Driven GUIs with Data Binding
      13. 23.13 Wrap-Up
    32. 24. WPF Graphics and Multimedia
      1. 24.1 Introduction
      2. 24.2 Controlling Fonts
      3. 24.3 Basic Shapes
      4. 24.4 Polygons and Polylines
      5. 24.5 Brushes
        1. ImageBrush
        2. VisualBrush and MediaElement
        3. Gradients
      6. 24.6 Transforms
      7. 24.7 WPF Customization: A Television GUI
        1. WPF Effects
        2. Creating Buttons on the TV
        3. Creating the TV Interface
        4. Creating the Reflection of the TV Screen
        5. Skewing the GUI Components to Create a 3-D Look
        6. Examining the Code-Behind Class
      8. 24.8 Animations
      9. 24.9 Speech Synthesis and Speech Recognition
        1. Instance Variables
        2. Constructor
        3. Method SpeechButton_Click
        4. Method Image_MouseDown
        5. Method myGrammar_SpeechRecognized
        6. Method DisplaySpeak
      10. 24.10 Wrap-Up
    33. 25. ATM Case Study, Part 1: Object-Oriented Design with the UML
      1. 25.1 Introduction
      2. 25.2 Examining the ATM Requirements Document
        1. Requirements Document
        2. Analyzing the ATM System
        3. Use Case Diagrams
        4. Designing the ATM System
        5. Web Resources
        6. Self-Review Exercises
      3. 25.3 Identifying the Classes in the ATM Requirements Document
        1. Identifying the Classes in a System
        2. Modeling Classes
        3. Self-Review Exercises
      4. 25.4 Identifying Class Attributes
        1. Identifying Attributes
        2. Modeling Attributes
        3. Self-Review Exercises
      5. 25.5 Identifying Objects’ States and Activities
        1. State Machine Diagrams
        2. Activity Diagrams
        3. Self-Review Exercises
      6. 25.6 Identifying Class Operations
        1. Identifying Operations
        2. Modeling Operations
        3. Operations of Class BankDatabase and Class Account
        4. Operations of Class Screen
        5. Operations of Class Keypad
        6. Operations of Class CashDispenser and Class DepositSlot
        7. Operations of Class ATM
        8. Identifying and Modeling Operation Parameters
        9. Self-Review Exercises
      7. 25.7 Identifying Collaboration Among Objects
        1. Identifying the Collaborations in a System
        2. Interaction Diagrams
        3. Communication Diagrams
        4. Sequence of Messages in a Communication Diagram
        5. Sequence Diagrams
        6. Self-Review Exercises
      8. 25.8 Wrap-Up
        1. Answers to Self-Review Exercises
    34. 26. ATM Case Study, Part 2: Implementing an OO Design in C#
      1. 26.1 Introduction
      2. 26.2 Starting to Program the Classes of the ATM System
        1. Visibility
        2. Navigability
        3. Implementing the ATM System from Its UML Design
        4. Self-Review Exercises
      3. 26.3 Incorporating Inheritance and Polymorphism into the ATM System
        1. Implementing the ATM System Design Incorporating Inheritance
        2. Self-Review Exercises
      4. 26.4 ATM Case Study Implementation
        1. 26.4.1 Class ATM
        2. 26.4.2 Class Screen
        3. 26.4.3 Class Keypad
        4. 26.4.4 Class CashDispenser
        5. 26.4.5 Class DepositSlot
        6. 26.4.6 Class Account
        7. 26.4.7 Class BankDatabase
        8. 26.4.8 Class Transaction
        9. 26.4.9 Class BalanceInquiry
        10. 26.4.10 Class Withdrawal
        11. 26.4.11 Class Deposit
        12. 26.4.12 Class ATMCaseStudy
      5. 26.5 Wrap-Up
        1. Answers to Self-Review Exercises
    35. A. Operator Precedence Chart
    36. B. Simple Types
      1. Additional Simple Type Information
    37. C. ASCII Character Set
    38. D. Number Systems
      1. D.1 Introduction
      2. D.2 Abbreviating Binary Numbers as Octal and Hexadecimal Numbers
      3. D.3 Converting Octal and Hexadecimal Numbers to Binary Numbers
      4. D.4 Converting from Binary, Octal or Hexadecimal to Decimal
      5. D.5 Converting from Decimal to Binary, Octal or Hexadecimal
      6. D.6 Negative Binary Numbers: Two’s Complement Notation
    39. E. UML 2: Additional Diagram Types
      1. E.1 Introduction
      2. E.2 Additional Diagram Types
    40. F. Unicode®
      1. F.1 Introduction
      2. F.2 Unicode Transformation Formats
      3. F.3 Characters and Glyphs
      4. F.4 Advantages/Disadvantages of Unicode
      5. F.5 Using Unicode
      6. F.6 Character Ranges
    41. G. Using the Visual Studio Debugger
      1. G.1 Introduction
      2. G.2 Breakpoints and the Continue Command
      3. G.3 DataTips and Visualizers
      4. G.4 The Locals and Watch Windows
      5. G.5 Controlling Execution Using the Step Into, Step Over, Step Out and Continue Commands
      6. G.6 Other Debugging Features
        1. G.6.1 Exception Assistant
        2. G.6.2 Just My Code™ Debugging
        3. G.6.3 Other Debugger Features
      7. G.7 Wrap-Up
    42. Index
    43. Code Snippets

    Product information

    • Title: C# 6 for Programmers, Sixth Edition
    • Author(s): Paul Deitel, Harvey Deitel
    • Release date: August 2016
    • Publisher(s): Pearson
    • ISBN: 9780134596396