You are previewing Visual C#® 2012: How to Program, Fifth Edition.
O'Reilly logo
Visual C#® 2012: How to Program, Fifth Edition

Book Description

Appropriate for all basic-to-intermediate level courses in Visual C# 2012 programming.

Created by world-renowned programming instructors Paul and Harvey Deitel, Visual C# 2012 How to Program, Fifth Edition introduces all facets of the C# 2012 language hands-on, through hundreds of working programs. This book has been thoroughly updated to reflect the major innovations Microsoft has incorporated in Visual C# 2012; all discussions and sample code have been carefully audited against the newest Visual C# language specification.

Students begin by getting comfortable with the C# Express 2012 IDE and basic Visual C# syntax. Next, they build their skills one step at a time, mastering control structures, classes, objects, methods, variables, arrays, and the core techniques of object-oriented programming. With this strong foundation in place, the Deitels introduce more sophisticated techniques, including searching, sorting, data structures, generics, and collections. Throughout, the authors show students how to make the most of Microsoft’s Visual Studio tools. A series of appendices provide essential programming reference material.

Table of Contents

  1. Title Page
  2. Copyright Page
  3. Deitel® Series Page
    1. How To Program Series
    2. Simply Series
    3. CourseSmart Web Books
    4. Deitel® Developer Series
    5. LiveLessons Video Learning Products
  4. Dedication
  5. Contents
  6. Preface
    1. Visual C#® 2012, the Visual Studio® 2012 IDE, .NET 4.5, Windows® 7 and Windows® 8
    2. Object-Oriented Programming
    3. Complete Code Examples
    4. Interesting, Entertaining and Challenging Exercises
    5. Illustrations and Figures
    6. Other Features
    7. Companion Website
    8. VideoNotes
    9. Book Overview and Chapter Dependencies
    10. Teaching Approach
    11. Obtaining the Software Used in Visual C# How to Program, 5/e
    12. Instructor Supplements
    13. Microsoft DreamSpark™
    14. Acknowledgments
    15. About the Authors
    16. Deitel® Dive-Into® Series Programming Languages Training
  7. Before You Begin
    1. Font and Naming Conventions
    2. Software
    3. Hardware and Software Requirements for the Visual Studio 2012 Express Editions
    4. Viewing File Extensions
    5. Obtaining the Code Examples
    6. Visual Studio Theme
    7. Displaying Line Numbers and Configuring Tabs
    8. Miscellaneous Notes
  8. 1. Introduction to Computers, the Internet and Visual C#
    1. 1.1. Introduction
    2. 1.2. Hardware and Moore’s Law
    3. 1.3. Data Hierarchy
    4. 1.4. Computer Organization
    5. 1.5. Machine Languages, Assembly Languages and High-Level Languages
    6. 1.6. Object Technology
    7. 1.7. Internet and World Wide Web
    8. 1.8. C#
    9. 1.9. Microsoft’s .NET
    10. 1.10. Microsoft’s Windows® Operating System
    11. 1.11. Windows Phone 8 for Smartphones
    12. 1.12. Windows Azure™ and Cloud Computing
    13. 1.13. Visual Studio Express 2012 Integrated Development Environment
    14. 1.14. Painter Test-Drive in Visual Studio Express 2012 for Windows Desktop
    15. 1.15. Painter Test-Drive in Visual Studio Express 2012 for Windows 8
    16. Self-Review Exercises
    17. Answers to Self-Review Exercises
    18. Exercises
    19. Making a Difference Exercises
  9. 2. Dive Into® Visual Studio Express 2012 for Windows Desktop
    1. 2.1. Introduction
    2. 2.2. Overview of the Visual Studio Express 2012 IDE
    3. 2.3. Menu Bar and Toolbar
    4. 2.4. Navigating the Visual Studio IDE
    5. 2.5. Using Help
    6. 2.6. Using Visual App Development to Create a Simple App that Displays Text and an Image
    7. 2.7. Wrap-Up
    8. 2.8. Web Resources
    9. Summary
    10. Terminology
    11. Self-Review Exercises
    12. Answers to Self-Review Exercises
    13. Exercises
  10. 3. Introduction to C# Apps
    1. 3.1. Introduction
    2. 3.2. A Simple C# App: Displaying a Line of Text
    3. 3.3. Creating a Simple App in Visual Studio
    4. 3.4. Modifying Your Simple C# App
    5. 3.5. Formatting Text with Console.Write and Console.WriteLine
    6. 3.6. Another C# App: Adding Integers
    7. 3.7. Memory Concepts
    8. 3.8. Arithmetic
    9. 3.9. Decision Making: Equality and Relational Operators
    10. 3.10. Wrap-Up
    11. Summary
    12. Terminology
    13. Self-Review Exercises
    14. Answers to Self-Review Exercises
    15. Exercises
    16. Making a Difference Exercises
  11. 4. Introduction to Classes, Objects, Methods and strings
    1. 4.1. Introduction
    2. 4.2. Classes, Objects, Methods, Properties and Instance Variables
    3. 4.3. Declaring a Class with a Method and Instantiating an Object of a Class
    4. 4.4. Declaring a Method with a Parameter
    5. 4.5. Instance Variables and Properties
    6. 4.6. UML Class Diagram with a Property
    7. 4.7. Software Engineering with Properties and set and get Accessors
    8. 4.8. Auto-Implemented Properties
    9. 4.9. Value Types vs. Reference Types
    10. 4.10. Initializing Objects with Constructors
    11. 4.11. Floating-Point Numbers and Type decimal
    12. 4.12. Wrap-Up
    13. Summary
    14. Terminology
    15. Self-Review Exercises
    16. Answers to Self-Review Exercises
    17. Exercises
    18. Making a Difference Exercises
  12. 5. Control Statements: Part 1
    1. 5.1. Introduction
    2. 5.2. Algorithms
    3. 5.3. Pseudocode
    4. 5.4. Control Structures
    5. 5.5. if Single-Selection Statement
    6. 5.6. if...else Double-Selection Statement
    7. 5.7. while Repetition Statement
    8. 5.8. Formulating Algorithms: Counter-Controlled Repetition
    9. 5.9. Formulating Algorithms: Sentinel-Controlled Repetition
    10. 5.10. Formulating Algorithms: Nested Control Statements
    11. 5.11. Compound Assignment Operators
    12. 5.12. Increment and Decrement Operators
    13. 5.13. Simple Types
    14. 5.14. Wrap-Up
    15. Summary
    16. Terminology
    17. Self-Review Exercises
    18. Answers to Self-Review Exercises
    19. Exercises
    20. Making a Difference Exercises
  13. 6. Control Statements: Part 2
    1. 6.1. Introduction
    2. 6.2. Essentials of Counter-Controlled Repetition
    3. 6.3. for Repetition Statement
    4. 6.4. Examples Using the for Statement
    5. 6.5. do...while Repetition Statement
    6. 6.6. switch Multiple-Selection Statement
    7. 6.7. break and continue Statements
    8. 6.8. Logical Operators
    9. 6.9. Structured-Programming Summary
    10. 6.10. Wrap-Up
    11. Summary
    12. Terminology
    13. Self-Review Exercises
    14. Answers to Self-Review Exercises
    15. Exercises
    16. Making a Difference Exercises
  14. 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
    4. 7.4. Declaring Methods with Multiple Parameters
    5. 7.5. Notes on Declaring and Using Methods
    6. 7.6. Method-Call Stack and Activation Records
    7. 7.7. Argument Promotion and Casting
    8. 7.8. The .NET Framework Class Library
    9. 7.9. Case Study: Random-Number Generation
    10. 7.10. Case Study: A Game of Chance; Introducing Enumerations
    11. 7.11. Scope of Declarations
    12. 7.12. Method Overloading
    13. 7.13. Optional Parameters
    14. 7.14. Named Parameters
    15. 7.15. Recursion
    16. 7.16. Passing Arguments: Pass-by-Value vs. Pass-by-Reference
    17. 7.17. Wrap-Up
    18. Summary
    19. Terminology
    20. Self-Review Exercises
    21. Answers to Self-Review Exercises
    22. Exercises
    23. Making a Difference Exercises
  15. 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
    5. 8.5. Case Study: Card Shuffling and Dealing Simulation
    6. 8.6. foreach Statement
    7. 8.7. Passing Arrays and Array Elements to Methods
    8. 8.8. Passing Arrays by Value and by Reference
    9. 8.9. Case Study: GradeBook Using an Array to Store Grades
    10. 8.10. Multidimensional Arrays
    11. 8.11. Case Study: GradeBook Using a Rectangular Array
    12. 8.12. Variable-Length Argument Lists
    13. 8.13. Using Command-Line Arguments
    14. 8.14. Wrap-Up
    15. Summary
    16. Terminology
    17. Self-Review Exercises
    18. Answers to Self-Review Exercises
    19. Exercises
    20. Special Section: Building Your Own Computer
    21. Making a Difference Exercise
  16. 9. Introduction to LINQ and the List Collection
    1. 9.1. Introduction
    2. 9.2. Querying an Array of int Values Using LINQ
    3. 9.3. Querying an Array of Employee Objects Using LINQ
    4. 9.4. Introduction to Collections
    5. 9.5. Querying a Generic Collection Using LINQ
    6. 9.6. Wrap-Up
    7. 9.7. Deitel LINQ Resource Center
    8. Summary
    9. Terminology
    10. Self-Review Exercises
    11. Answers to Self-Review Exercises
    12. Exercises
  17. 10. Classes and Objects: A Deeper Look
    1. 10.1. Introduction
    2. 10.2. Time Class Case Study
    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
    6. 10.6. Default and Parameterless Constructors
    7. 10.7. Composition
    8. 10.8. Garbage Collection and Destructors
    9. 10.9. static Class Members
    10. 10.10. readonly Instance Variables
    11. 10.11. Data Abstraction and Encapsulation
    12. 10.12. Class View and Object Browser
    13. 10.13. Object Initializers
    14. 10.14. Wrap-Up
    15. Summary
    16. Terminology
    17. Self-Review Exercises
    18. Answers to Self-Review Exercises
    19. Exercises
  18. 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
    5. 11.5. Constructors in Derived Classes
    6. 11.6. Software Engineering with Inheritance
    7. 11.7. Class object
    8. 11.8. Wrap-Up
    9. Summary
    10. Terminology
    11. Self-Review Exercises
    12. Answers to Self-Review Exercises
    13. Exercises
  19. 12. OOP: Polymorphism, Interfaces and Operator Overloading
    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
    6. 12.6. sealed Methods and Classes
    7. 12.7. Case Study: Creating and Using Interfaces
    8. 12.8. Operator Overloading
    9. 12.9. Wrap-Up
    10. Summary
    11. Terminology
    12. Self-Review Exercises
    13. Answers to Self-Review Exercises
    14. Exercises
    15. Making a Difference Exercise
  20. 13. Exception Handling: A Deeper Look
    1. 13.1. Introduction
    2. 13.2. Example: Divide by Zero without Exception Handling
    3. 13.3. Example: Handling DivideByZeroExceptions and FormatExceptions
    4. 13.4. .NET Exception Hierarchy
    5. 13.5. finally Block
    6. 13.6. The using Statement
    7. 13.7. Exception Properties
    8. 13.8. User-Defined Exception Classes
    9. 13.9. Wrap-Up
    10. Summary
    11. Terminology
    12. Self-Review Exercises
    13. Answers to Self-Review Exercises
    14. Exercises
  21. 14. Graphical User Interfaces with Windows Forms: Part 1
    1. 14.1. Introduction
    2. 14.2. Windows Forms
    3. 14.3. Event Handling
    4. 14.4. Control Properties and Layout
    5. 14.5. Labels, TextBoxes and Buttons
    6. 14.6. GroupBoxes and Panels
    7. 14.7. CheckBoxes and 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
    14. Summary
    15. Terminology
    16. Self-Review Exercises
    17. Answers To Self-Review Exercises
    18. Exercises
    19. Making a Difference Exercises
  22. 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
    16. Summary
    17. Terminology
    18. Self-Review Exercises
    19. Answers to Self-Review Exercises
    20. Exercises
  23. 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. (Online) Introduction to Regular Expressions
    16. 16.16. Wrap-Up
    17. Summary
    18. Terminology
    19. Self-Review Exercises
    20. Answers to Self-Review Exercises
    21. Exercises
    22. Making a Difference Exercises
  24. 17. Files and Streams
    1. 17.1. Introduction
    2. 17.2. Data Hierarchy
    3. 17.3. Files and Streams
    4. 17.4. Classes File and Directory
    5. 17.5. Creating a Sequential-Access Text File
    6. 17.6. Reading Data from a Sequential-Access Text File
    7. 17.7. Case Study: Credit Inquiry Program
    8. 17.8. Serialization
    9. 17.9. Creating a Sequential-Access File Using Object Serialization
    10. 17.10. Reading and Deserializing Data from a Binary File
    11. 17.11. Wrap-Up
    12. Summary
    13. Terminology
    14. Self-Review Exercises
    15. Answers to Self-Review Exercises
    16. Exercises
    17. Making a Difference Exercise
  25. 18. Searching and Sorting
    1. 18.1. Introduction
    2. 18.2. Searching Algorithms
    3. 18.3. Sorting Algorithms
    4. 18.4. Summary of the Efficiency of Searching and Sorting Algorithms
    5. 18.5. Wrap-Up
    6. Summary
    7. Terminology
    8. Self-Review Exercises
    9. Answers to Self-Review Exercises
    10. Exercises
  26. 19. Data Structures
    1. 19.1. Introduction
    2. 19.2. Simple-Type structs, Boxing and Unboxing
    3. 19.3. Self-Referential Classes
    4. 19.4. Linked Lists
    5. 19.5. Stacks
    6. 19.6. Queues
    7. 19.7. Trees
    8. 19.8. Wrap-Up
    9. Summary
    10. Terminology
    11. Self-Review Exercises
    12. Answers to Self-Review Exercises
    13. Exercises
  27. 20. Generics
    1. 20.1. Introduction
    2. 20.2. Motivation for Generic Methods
    3. 20.3. Generic-Method Implementation
    4. 20.4. Type Constraints
    5. 20.5. Overloading Generic Methods
    6. 20.6. Generic Classes
    7. 20.7. Wrap-Up
    8. Summary
    9. Terminology
    10. Self-Review Exercises
    11. Answers to Self-Review Exercises
    12. Exercises
  28. 21. Collections
    1. 21.1. Introduction
    2. 21.2. Collections Overview
    3. 21.3. Class Array and Enumerators
    4. 21.4. Nongeneric Collections
    5. 21.5. Generic Collections
    6. 21.6. Covariance and Contravariance for Generic Types
    7. 21.7. Wrap-Up
    8. Summary
    9. Terminology
    10. Self-Review Exercises
    11. Answers to Self-Review Exercises
    12. Exercises
  29. 22. Databases and LINQ
    1. 22.1. Introduction
    2. 22.2. Relational Databases
    3. 22.3. A Books Database
    4. 22.4. LINQ to Entities and the ADO.NET Entity Framework
    5. 22.5. Querying a Database with LINQ
    6. 22.6. Dynamically Binding Query Results
    7. 22.7. Retrieving Data from Multiple Tables with LINQ
    8. 22.8. Creating a Master/Detail View App
    9. 22.9. Address Book Case Study
    10. 22.10. Tools and Web Resources
    11. 22.11. Wrap-Up
    12. Summary
    13. Terminology
    14. Self-Review Exercises
    15. Answers to Self-Review Exercises
    16. Exercises
  30. 23. Web App Development with ASP.NET
    1. 23.1. Introduction
    2. 23.2. Web Basics
    3. 23.3. Multitier App Architecture
    4. 23.4. Your First Web App
    5. 23.5. Standard Web Controls: Designing a Form
    6. 23.6. Validation Controls
    7. 23.7. Session Tracking
    8. 23.8. Case Study: Database-Driven ASP.NET Guestbook
    9. 23.9. Online Case Study: ASP.NET AJAX
    10. 23.10. Online Case Study: Password-Protected Books Database App
    11. 23.11. Wrap-Up
    12. Summary
    13. Terminology
    14. Self-Review Exercises
    15. Answers to Self-Review Exercises
    16. Exercises
  31. Chapters on the Web
  32. A. Operator Precedence Chart
  33. B. Simple Types
    1. Additional Simple Type Information
  34. C. ASCII Character Set
  35. Appendices on the Web
  36. Index