Microsoft® Visual C#® 2008 Step by Step

Book description

Get the hands-on, step-by-step guide to learning the latest enhancements in Microsoft Visual C# 2008. Visual C#, one of the tools in Microsoft Visual Studio 2008, is a modern programming language designed to deliver a productive environment for creating business frameworks and reusable object-oriented components. Whether you’re a beginning programmer or new to the Visual C# programming language, you’ll learn how to use the fundamental features of Visual Studio 2008 and gain a basic understanding of the latest enhancement of the Visual C# language. You’ll work at your own pace through hands-on, learn-by-doing exercises, get started creating components and working Windows applications, and build your knowledge as you start creating your first Visual C#–based applications. You’ll also explore how to create data management and Web-based applications. In each chapter, work through learn-by-doing exercises that demonstrate how, when, and why to use the many features of the Visual C# rapid application development environment. Includes a companion CD with code samples, data sets, and a fully searchable eBook.

For customers who purchase an ebook version of this title, instructions for downloading the CD files can be found in the ebook.

Table of contents

  1. Microsoft® Visual C#® 2008 Step by Step
  2. A Note Regarding Supplemental Files
  3. Acknowledgments
  4. Introduction
    1. Who This Book Is For
    2. Finding Your Best Starting Point in This Book
    3. Conventions and Features in This Book
      1. Conventions
      2. Other Features
    4. System Requirements
    5. Code Samples
      1. Installing the Code Samples
      2. Using the Code Samples
    6. Uninstalling the Code Samples
    7. Support for This Book
      1. Questions and Comments
  5. I. Introducing Microsoft Visual C# and Microsoft Visual Studio 2008
    1. 1. Welcome to C#
      1. Beginning Programming with the Visual Studio 2008 Environment
      2. Writing Your First Program
      3. Using Namespaces
      4. Creating a Graphical Application
      5. Chapter 1 Quick Reference
    2. 2. Working with Variables, Operators, and Expressions
      1. Understanding Statements
      2. Using Identifiers
      3. Identifying Keywords
      4. Using Variables
        1. Naming Variables
        2. Declaring Variables
      5. Working with Primitive Data Types
        1. Displaying Primitive Data Type Values
      6. Using Arithmetic Operators
        1. Operators and Types
        2. Examining Arithmetic Operators
        3. Controlling Precedence
        4. Using Associativity to Evaluate Expressions
        5. Associativity and the Assignment Operator
      7. Incrementing and Decrementing Variables
        1. Prefix and Postfix
      8. Declaring Implicitly Typed Local Variables
      9. Chapter 2 Quick Reference
    3. 3. Writing Methods and Applying Scope
      1. Declaring Methods
        1. Specifying the Method Declaration Syntax
        2. Writing return Statements
        3. Calling Methods
        4. Specifying the Method Call Syntax
      2. Applying Scope
        1. Defining Local Scope
        2. Defining Class Scope
        3. Overloading Methods
      3. Writing Methods
      4. Chapter 3 Quick Reference
    4. 4. Using Decision Statements
      1. Declaring Boolean Variables
      2. Using Boolean Operators
        1. Understanding Equality and Relational Operators
        2. Understanding Conditional Logical Operators
        3. Summarizing Operator Precedence and Associativity
      3. Using if Statements to Make Decisions
        1. Understanding if Statement Syntax
        2. Using Blocks to Group Statements
        3. Cascading if Statements
      4. Using switch Statements
        1. Understanding switch Statement Syntax
        2. Following the switch Statement Rules
      5. Chapter 4 Quick Reference
    5. 5. Using Compound Assignment and Iteration Statements
      1. Using Compound Assignment Operators
      2. Writing while Statements
      3. Writing for Statements
        1. Understanding for Statement Scope
      4. Writing do Statements
      5. Chapter 5 Quick Reference
    6. 6. Managing Errors and Exceptions
      1. Coping with Errors
      2. Trying Code and Catching Exceptions
        1. Handling an Exception
          1. Unhandled Exceptions
        2. Using Multiple catch Handlers
        3. Catching Multiple Exceptions
      3. Using Checked and Unchecked Integer Arithmetic
        1. Writing Checked Statements
        2. Writing Checked Expressions
      4. Throwing Exceptions
      5. Using a finally Block
      6. Chapter 6 Quick Reference
  6. II. Understanding the C# Language
    1. 7. Creating and Managing Classes and Objects
      1. Understanding Classification
      2. The Purpose of Encapsulation
      3. Defining and Using a Class
      4. Controlling Accessibility
      5. Working with Constructors
        1. Overloading Constructors
      6. Understanding static Methods and Data
        1. Creating a Shared Field
        2. Creating a static Field by Using the const Keyword
      7. Chapter 7 Quick Reference
    2. 8. Understanding Values and References
      1. Copying Value Type Variables and Classes
      2. Understanding Null Values and Nullable Types
        1. Using Nullable Types
        2. Understanding the Properties of Nullable Types
      3. Using ref and out Parameters
        1. Creating ref Parameters
        2. Creating out Parameters
      4. How Computer Memory Is Organized
        1. Using the Stack and the Heap
      5. The System.Object Class
      6. Boxing
      7. Unboxing
      8. Casting Data Safely
        1. The is Operator
        2. The as Operator
      9. Chapter 8 Quick Reference
    3. 9. Creating Value Types with Enumerations and Structures
      1. Working with Enumerations
        1. Declaring an Enumeration
        2. Using an Enumeration
        3. Choosing Enumeration Literal Values
        4. Choosing an Enumeration’s Underlying Type
      2. Working with Structures
        1. Declaring a Structure
        2. Understanding Structure and Class Differences
        3. Declaring Structure Variables
        4. Understanding Structure Initialization
        5. Copying Structure Variables
      3. Chapter 9 Quick Reference
    4. 10. Using Arrays and Collections
      1. What Is an Array?
        1. Declaring Array Variables
        2. Creating an Array Instance
      2. Initializing Array Variables
        1. Creating an Implicitly Typed Array
        2. Accessing an Individual Array Element
        3. Iterating Through an Array
        4. Copying Arrays
      3. What Are Collection Classes?
        1. The ArrayList Collection Class
        2. The Queue Collection Class
        3. The Stack Collection Class
        4. The Hashtable Collection Class
      4. The SortedList Collection Class
        1. Using Collection Initializers
        2. Comparing Arrays and Collections
        3. Using Collection Classes to Play Cards
      5. Chapter 10 Quick Reference
    5. 11. Understanding Parameter Arrays
      1. Using Array Arguments
        1. Declaring a params Array
        2. Using params object[ ]
          1. The Console.WriteLine Method
        3. Using a params Array
      2. Chapter 11 Quick Reference
    6. 12. Working with Inheritance
      1. What Is Inheritance?
      2. Using Inheritance
        1. Base Classes and Derived Classes
        2. Calling Base Class Constructors
        3. Assigning Classes
        4. Declaring new Methods
        5. Declaring Virtual Methods
        6. Declaring override Methods
        7. Understanding protected Access
      3. Understanding Extension Methods
      4. Chapter 12 Quick Reference
    7. 13. Creating Interfaces and Defining Abstract Classes
      1. Understanding Interfaces
        1. Interface Syntax
      2. Interface Restrictions
        1. Implementing an Interface
        2. Referencing a Class Through Its Interface
        3. Working with Multiple Interfaces
      3. Abstract Classes
        1. Abstract Methods
      4. Sealed Classes
        1. Sealed Methods
      5. Implementing an Extensible Framework
      6. Summarizing Keyword Combinations
      7. Chapter 13 Quick Reference
    8. 14. Using Garbage Collection and Resource Management
      1. The Life and Times of an Object
        1. Writing Destructors
        2. Why Use the Garbage Collector?
        3. How Does the Garbage Collector Work?
        4. Recommendations
      2. Resource Management
        1. Disposal Methods
        2. Exception-Safe Disposal
        3. The using Statement
        4. Calling the Dispose Method from a Destructor
      3. Making Code Exception-Safe
      4. Chapter 14 Quick Reference
  7. III. Creating Components
    1. 15. Implementing Properties to Access Fields
      1. Implementing Encapsulation by Using Methods
      2. What Are Properties?
        1. Using Properties
        2. Read-Only Properties
        3. Write-Only Properties
        4. Property Accessibility
      3. Understanding the Property Restrictions
        1. Using Properties Appropriately
      4. Declaring Interface Properties
        1. Using Properties in a Windows Application
      5. Generating Automatic Properties
      6. Initializing Objects by Using Properties
      7. Chapter 15 Quick Reference
    2. 16. Using Indexers
      1. What Is an Indexer?
        1. An Example That Doesn’t Use Indexers
        2. The Bitwise and Shift Operators
        3. The Same Example Using Indexers
        4. Understanding Indexer Accessors
        5. Comparing Indexers and Arrays
          1. Properties, Arrays, and Indexers
      2. Indexers in Interfaces
      3. Using Indexers in a Windows Application
      4. Chapter 16 Quick Reference
    3. 17. Interrupting Program Flow and Handling Events
      1. Declaring and Using Delegates
        1. The Automated Factory Scenario
        2. Implementing the Factory Without Using Delegates
        3. Implementing the Factory by Using a Delegate
        4. Using Delegates
      2. Lambda Expressions and Delegates
        1. Creating a Method Adapter
        2. Using a Lambda Expression as an Adapter
        3. The Form of Lambda Expressions
      3. Enabling Notifications with Events
        1. Declaring an Event
        2. Subscribing to an Event
      4. Unsubscribing from an Event
        1. Raising an Event
      5. Understanding WPF User Interface Events
        1. Using Events
      6. Chapter 17 Quick Reference
    4. 18. Introducing Generics
      1. The Problem with objects
      2. The Generics Solution
        1. Generics vs. Generalized Classes
        2. Generics and Constraints
      3. Creating a Generic Class
        1. The Theory of Binary Trees
        2. Building a Binary Tree Class by Using Generics
      4. Creating a Generic Method
        1. Defining a Generic Method to Build a Binary Tree
      5. Chapter 18 Quick Reference
    5. 19. Enumerating Collections
      1. Enumerating the Elements in a Collection
        1. Manually Implementing an Enumerator
        2. Implementing the IEnumerable Interface
      2. Implementing an Enumerator by Using an Iterator
        1. A Simple Iterator
        2. Defining an Enumerator for the Tree<TItem> Class by Using an Iterator
      3. Chapter 19 Quick Reference
    6. 20. Querying In-Memory Data by Using Query Expressions
      1. What Is Language Integrated Query (LINQ)?
      2. Using LINQ in a C# Application
        1. Selecting Data
        2. Filtering Data
        3. Ordering, Grouping, and Aggregating Data
        4. Joining Data
        5. Using Query Operators
        6. Querying Data in Tree<TItem> Objects
        7. LINQ and Deferred Evaluation
      3. Chapter 20 Quick Reference
    7. 21. Operator Overloading
      1. Understanding Operators
        1. Operator Constraints
        2. Overloaded Operators
        3. Creating Symmetric Operators
          1. Operators and Language Interoperability
      2. Understanding Compound Assignment
      3. Declaring Increment and Decrement Operators
        1. Providing Built-In Conversions
          1. Operators in Structures and Classes
      4. Defining Operator Pairs
      5. Implementing an Operator
      6. Understanding Conversion Operators
        1. Providing Built-In Conversions
        2. Implementing User-Defined Conversion Operators
        3. Creating Symmetric Operators, Revisited
        4. Adding an Implicit Conversion Operator
      7. Chapter 21 Quick Reference
  8. IV. Working with Windows Applications
    1. 22. Introducing Windows Presentation Foundation
      1. Creating a WPF Application
        1. Creating a Windows Presentation Foundation Application
      2. Adding Controls to the Form
        1. Using WPF Controls
        2. Changing Properties Dynamically
      3. Handling Events in a WPF Form
        1. Processing Events in Windows Forms
      4. Chapter 22 Quick Reference
    2. 23. Working with Menus and Dialog Boxes
      1. Menu Guidelines and Style
      2. Menus and Menu Events
        1. Creating a Menu
        2. Handling Menu Events
      3. Shortcut Menus
        1. Creating Shortcut Menus
      4. Windows Common Dialog Boxes
        1. Using the SaveFileDialog Class
      5. Chapter 23 Quick Reference
    3. 24. Performing Validation
      1. Validating Data
        1. Strategies for Validating User Input
      2. An Example—Customer Information Maintenance
        1. Performing Validation by Using Data Binding
        2. Changing the Point at Which Validation Occurs
      3. Chapter 24 Quick Reference
  9. V. Managing Data
    1. 25. Querying Information in a Database
      1. Querying a Database by Using ADO.NET
        1. The Northwind Database
        2. Creating the Database
        3. Using ADO.NET to Query Order Information
      2. Querying a Database by Using DLINQ
        1. Defining an Entity Class
        2. Creating and Running a DLINQ Query
        3. Deferred and Immediate Fetching
        4. Joining Tables and Creating Relationships
        5. Deferred and Immediate Fetching Revisited
        6. Defining a Custom DataContext Class
        7. Using DLINQ to Query Order Information
      3. Chapter 25 Quick Reference
    2. 26. Displaying and Editing Data by Using Data Binding
      1. Using Data Binding with DLINQ
      2. Using DLINQ to Modify Data
        1. Updating Existing Data
        2. Handling Conflicting Updates
        3. Adding and Deleting Data
      3. Chapter 26 Quick Reference
  10. VI. Building Web Applications
    1. 27. Introducing ASP.NET
      1. Understanding the Internet as an Infrastructure
        1. Understanding Web Server Requests and Responses
        2. Managing State
        3. Understanding ASP.NET
      2. Creating Web Applications with ASP.NET
        1. Building an ASP.NET Application
        2. Understanding Server Controls
        3. Creating and Using a Theme
          1. Defining a Theme
          2. Applying a Theme
      3. Chapter 27 Quick Reference
    2. 28. Understanding Web Forms Validation Controls
      1. Comparing Server and Client Validations
        1. Validating Data at the Web Server
        2. Validating Data in the Web Browser
        3. Implementing Client Validation
      2. Chapter 28 Quick Reference
    3. 29. Protecting a Web Site and Accessing Data with Web Forms
      1. Managing Security
        1. Understanding Forms-Based Security
        2. Implementing Forms-Based Security
      2. Querying and Displaying Data
        1. Understanding the Web Forms GridView Control
        2. Displaying Customer and Order History Information
        3. Paging Data
      3. Editing Data
        1. Updating Rows Through a GridView Control
      4. Navigating Between Forms
      5. Chapter 29 Quick Reference
    4. 30. Creating and Using a Web Service
      1. What Is a Web Service?
        1. The Role of SOAP
        2. What Is the Web Services Description Language?
        3. Nonfunctional Requirements of Web Services
        4. The Role of Windows Communication Foundation
      2. Building a Web Service
        1. Creating the ProductsService Web Service
      3. Web Services, Clients, and Proxies
        1. Talking SOAP: The Difficult Way
        2. Talking SOAP: The Easy Way
        3. Consuming the ProductsService Web Service
      4. Chapter 30 Quick Reference
  11. Index
  12. About the Author
  13. Copyright

Product information

  • Title: Microsoft® Visual C#® 2008 Step by Step
  • Author(s): John Sharp
  • Release date: December 2007
  • Publisher(s): Microsoft Press
  • ISBN: 9780735634701