Microsoft Visual C# 2010 Step by Step

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Covers the fundamentals of Visual C# and how to use it to build .NET-connected applications, covering topics including syntax, Web services, and operators.

Author(s): John Sharp
Year: 2010

Language: English
Pages: 748

Cover
Copyright page
Acknowledgments
Introduction
Who This Book Is For
Finding Your Best Starting Point in This Book
Conventions and Features in This Book
Conventions
Other Features
Prerelease Software
Hardware and Software Requirements
Code Samples
Installing the Code Samples
Using the Code Samples
Uninstalling the Code Samples
Find Additional Content Online
Support for This Book
Questions and Comments
Part I:
Introducing Microsoft Visual C# and Microsoft Visual Studio 2010
Chapter 1:
Welcome to C#
Beginning Programming with the Visual Studio 2010 Environment
Writing Your First Program
Using Namespaces
Creating a Graphical Application
Chapter 1 Quick Reference
Chapter 2:
Working with Variables, Operators, and Expressions
Understanding Statements
Using Identifiers
Identifying Keywords
Using Variables
Naming Variables
Declaring Variables
Working with Primitive Data Types
Unassigned Local Variables
Displaying Primitive Data Type Values
Using Arithmetic Operators
Operators and Types
Examining Arithmetic Operators
Controlling Precedence
Using Associativity to Evaluate Expressions
Associativity and the Assignment Operator
Incrementing and Decrementing Variables
Prefix and Postfix
Declaring Implicitly Typed Local Variables
Chapter 2 Quick Reference
Chapter 3:
Writing Methods and Applying Scope
Creating Methods
Declaring a Method
Returning Data from a Method
Calling Methods
Specifying the Method Call Syntax
Applying Scope
Defining Local Scope
Defining Class Scope
Overloading Methods
Writing Methods
Using Optional Parameters and Named Arguments
Defining Optional Parameters
Passing Named Arguments
Resolving Ambiguities with Optional Parameters and Named Arguments
Chapter 3 Quick Reference
Chapter 4:
Using Decision Statements
Declaring Boolean Variables
Using Boolean Operators
Understanding Equality and Relational Operators
Understanding Conditional Logical Operators
Short-Circuiting
Summarizing Operator Precedence and Associativity
Using if Statements to Make Decisions
Understanding if Statement Syntax
Using Blocks to Group Statements
Cascading if Statements
Using switch Statements
Understanding switch Statement Syntax
Following the switch Statement Rules
Chapter 4 Quick Reference
Chapter 5:
Using Compound Assignment and Iteration Statements
Using Compound Assignment Operators
Writing while Statements
Writing for Statements
Understanding for Statement Scope
Writing do Statements
Chapter 5 Quick Reference
Chapter 6:
Managing Errors and Exceptions
Coping with Errors
Trying Code and Catching Exceptions
Unhandled Exceptions
Using Multiple catch Handlers
Catching Multiple Exceptions
Using Checked and Unchecked Integer Arithmetic
Writing Checked Statements
Writing Checked Expressions
Throwing Exceptions
Using a finally Block
Chapter 6 Quick Reference
Part II:
Understanding the C# Language
Chapter 7:
Creating and Managing Classes and Objects
Understanding Classification
The Purpose of Encapsulation
Defining and Using a Class
Controlling Accessibility
Working with Constructors
Overloading Constructors
Understanding static Methods and Data
Creating a Shared Field
Creating a static Field by Using the const Keyword
Static Classes
Anonymous Classes
Chapter 7 Quick Reference
Chapter 8:
Understanding Values and References
Copying Value Type Variables and Classes
Understanding Null Values and Nullable Types
Using Nullable Types
Understanding the Properties of Nullable Types
Using ref and out Parameters
Creating ref Parameters
Creating out Parameters
How Computer Memory Is Organized
Using the Stack and the Heap
The System.Object Class
Boxing
Unboxing
Casting Data Safely
The is Operator
The as Operator
Chapter 8 Quick Reference
Chapter 9:
Creating Value Types with Enumerations and Structures
Working with Enumerations
Declaring an Enumeration
Using an Enumeration
Choosing Enumeration Literal Values
Choosing an Enumeration’s Underlying Type
Working with Structures
Declaring a Structure
Understanding Structure and Class Differences
Declaring Structure Variables
Understanding Structure Initialization
Copying Structure Variables
Chapter 9 Quick Reference
Chapter 10:
Using Arrays and Collections
What Is an Array?
Declaring Array Variables
Creating an Array Instance
Initializing Array Variables
Creating an Implicitly Typed Array
Accessing an Individual Array Element
Iterating Through an Array
Copying Arrays
Using Multidimensional Arrays
Using Arrays to Play Cards
What Are Collection Classes?
The ArrayList Collection Class
The Queue Collection Class
The Stack Collection Class
The Hashtable Collection Class
The SortedList Collection Class
Using Collection Initializers
Comparing Arrays and Collections
Using Collection Classes to Play Cards
Chapter 10 Quick Reference
Chapter 11:
Understanding Parameter Arrays
Using Array Arguments
Declaring a params Array
Using params object[ ]
Using a params Array
Comparing Parameters Arrays and Optional Parameters
Chapter 11 Quick Reference
Chapter 12:
Working with Inheritance
What Is Inheritance?
Using Inheritance
Calling Base Class Constructors
Assigning Classes
Declaring new Methods
Declaring Virtual Methods
Declaring override Methods
Understanding protected Access
Understanding Extension Methods
Chapter 12 Quick Reference
Chapter 13:
Creating Interfaces and Defining Abstract Classes
Understanding Interfaces
Defining an Interface
Implementing an Interface
Referencing a Class Through Its Interface
Working with Multiple Interfaces
Explicitly Implementing an Interface
Interface Restrictions
Defining and Using Interfaces
Abstract Classes
Abstract Methods
Sealed Classes
Sealed Methods
Implementing and Using an Abstract Class
Chapter 13 Quick Reference
Chapter 14:
Using Garbage Collection and Resource Management
The Life and Times of an Object
Writing Destructors
Why Use the Garbage Collector?
How Does the Garbage Collector Work?
Recommendations
Resource Management
Disposal Methods
Exception-Safe Disposal
The using Statement
Calling the Dispose Method from a Destructor
Implementing Exception-Safe Disposal
Chapter 14 Quick Reference
Part III:
Creating Components
Chapter 15:
Implementing Properties to Access Fields
Implementing Encapsulation by Using Methods
What Are Properties?
Using Properties
Read-Only Properties
Write-Only Properties
Property Accessibility
Understanding the Property Restrictions
Declaring Interface Properties
Using Properties in a Windows Application
Generating Automatic Properties
Initializing Objects by Using Properties
Chapter 15 Quick Reference
Chapter 16:
Using Indexers
What Is an Indexer?
An Example That Doesn’t Use Indexers
The Same Example Using Indexers
Understanding Indexer Accessors
Comparing Indexers and Arrays
Indexers in Interfaces
Using Indexers in a Windows Application
Chapter 16 Quick Reference
Chapter 17:
Interrupting Program Flow and Handling Events
Declaring and Using Delegates
The Automated Factory Scenario
Implementing the Factory Without Using Delegates
Implementing the Factory by Using a Delegate
Using Delegates
Lambda Expressions and Delegates
Creating a Method Adapter
Using a Lambda Expression as an Adapter
The Form of Lambda Expressions
Enabling Notifications with Events
Declaring an Event
Subscribing to an Event
Unsubscribing from an Event
Raising an Event
Understanding WPF User Interface Events
Using Events
Chapter 17 Quick Reference
Chapter 18:
Introducing Generics
The Problem with objects
The Generics Solution
Generics vs. Generalized Classes
Generics and Constraints
Creating a Generic Class
The Theory of Binary Trees
Building a Binary Tree Class by Using Generics
Creating a Generic Method
Defining a Generic Method to Build a Binary Tree
Variance and Generic Interfaces
Covariant Interfaces
Contravariant Interfaces
Chapter 18 Quick Reference
Chapter 19:
Enumerating Collections
Enumerating the Elements in a Collection
Manually Implementing an Enumerator
Implementing the IEnumerable Interface
Implementing an Enumerator by Using an Iterator
A Simple Iterator
Defining an Enumerator for the Tree Class by Using an Iterator
Chapter 19 Quick Reference
Chapter 20:
Querying In-Memory Data by Using Query Expressions
What Is Language Integrated Query?
Using LINQ in a C# Application
Selecting Data
Filtering Data
Ordering, Grouping, and Aggregating Data
Joining Data
Using Query Operators
Querying Data in Tree Objects
LINQ and Deferred Evaluation
Chapter 20 Quick Reference
Chapter 21:
Operator Overloading
Understanding Operators
Operator Constraints
Overloaded Operators
Creating Symmetric Operators
Understanding Compound Assignment Evaluation
Declaring Increment and Decrement Operators
Comparing Operators in Structures and Classes
Defining Operator Pairs
Implementing Operators
Understanding Conversion Operators
Providing Built-in Conversions
Implementing User-Defined Conversion Operators
Creating Symmetric Operators, Revisited
Writing Conversion Operators
Chapter 21 Quick Reference
Part IV:
Building Windows Presentation Foundation Applications
Chapter 22:
Introducing Windows Presentation Foundation
Creating a WPF Application
Building the WPF Application
Adding Controls to the Form
Using WPF Controls
Changing Properties Dynamically
Handling Events in a WPF Form
Processing Events in Windows Forms
Chapter 22 Quick Reference
Chapter 23:
Gathering User Input
Menu Guidelines and Style
Menus and Menu Events
Creating a Menu
Handling Menu Events
Shortcut Menus
Creating Shortcut Menus
Windows Common Dialog Boxes
Using the SaveFileDialog Class
Improving Responsiveness in a WPF Application
Chapter 23 Quick Reference
Chapter 24:
Performing Validation
Validating Data
Strategies for Validating User Input
An Example—Order Tickets for Events
Performing Validation by Using Data Binding
Changing the Point at Which Validation Occurs
Chapter 24 Quick Reference
Part V:
Managing Data
Chapter 25:
Querying Information in a Database
Querying a Database by Using ADO.NET
The Northwind Database
Creating the Database
Using ADO.NET to Query Order Information
Querying a Database by Using LINQ to SQL
Defining an Entity Class
Creating and Running a LINQ to SQL Query
Deferred and Immediate Fetching
Joining Tables and Creating Relationships
Deferred and Immediate Fetching Revisited
Defining a Custom DataContext Class
Using LINQ to SQL to Query Order Information
Chapter 25 Quick Reference
Chapter 26:
Displaying and Editing Data by Using the Entity Framework and Data Binding
Using Data Binding with the Entity Framework
Using Data Binding to Modify Data
Updating Existing Data
Handling Conflicting Updates
Adding and Deleting Data
Chapter 26 Quick Reference
Part VI:
Building Professional Solutions with Visual Studio 2010
Chapter 27:
Introducing the Task Parallel Library
Why Perform Multitasking by Using Parallel Processing?
The Rise of the Multicore Processor
Implementing Multitasking in a Desktop Application
Tasks, Threads, and the ThreadPool
Creating, Running, and Controlling Tasks
Using the Task Class to Implement Parallelism
Abstracting Tasks by Using the Parallel Class
Returning a Value from a Task
Using Tasks and User Interface Threads Together
Canceling Tasks and Handling Exceptions
The Mechanics of Cooperative Cancellation
Handling Task Exceptions by Using the AggregateException Class
Using Continuations with Canceled and Faulted Tasks
Chapter 27 Quick Reference
Chapter 28:
Performing Parallel Data Access
Using PLINQ to Parallelize Declarative Data Access
Using PLINQ to Improve Performance While Iterating Through a Collection
Specifying Options for a PLINQ Query
Canceling a PLINQ Query
Synchronizing Concurrent Imperative Data Access
Locking Data
Synchronization Primitives in the Task Parallel Library
Cancellation and the Synchronization Primitives
The Concurrent Collection Classes
Using a Concurrent Collection and a Lock to Implement Thread-Safe Data Access
Chapter 28 Quick Reference
Chapter 29:
Creating and Using a Web Service
What Is a Web Service?
The Role of Windows Communication Foundation
Web Service Architectures
SOAP Web Services
REST Web Services
Building Web Services
Creating the ProductInformation SOAP Web Service
SOAP Web Services, Clients, and Proxies
Consuming the ProductInformation SOAP Web Service
Creating the ProductDetails REST Web Service
Consuming the ProductDetails REST Web Service
Chapter 29 Quick Reference
Appendix:
Interoperating with Dynamic Languages
Summary
Index
About the Author
Survey page