Programming C# 3.0: Best-Selling Guide to Building Windows and Web Applications with C# 3.0

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"

Written by popular author and .NET expert Jesse Liberty, this thoroughly updated tutorial for beginning to intermediate programmers covers the latest release of Microsoft's popular C# language (C# 3.0) and the newest .NET platform for developing Windows and web applications. Our bestselling Programming C# 3.0, now in its fifth edition, is a world-class tutorial that goes well beyond the documentation otherwise available. Liberty doesn't just teach C#; he tells the complete story of the C# language and how it integrates with all of .NET programming, so that you can get started creating professional quality web and Windows applications. This book: Provides a comprehensive tutorial in C# and .NET programming that also serves as a useful reference you'll want by your side while you're working Covers all of the new features of the language, thoroughly integrated into every chapter, rather than tacked on at the end Provides insight into best practices and insight into real world programming by a professional programmer who worked with C# as an independent contractor for nearly a decade before joining Microsoft as a Senior Program Manager Every chapter in this book has been totally revised, and the entire book has been reorganized to respond to the significant changes in the language Full coverage, from the ground up of LINQ (Language Integrated Query) and other C# 3.0 language innovations to speed up development tasks Explains how to use C# in creating Web Applications as well as Windows Applications, using both the new Windows Presentation Foundation (WPF) and the older WinForms technology This new edition of Programming C# 3.0 is for working programmers who want to develop proficiency in Microsoft's most important language. No prior .NET experience is required for you to get started. There's no time like the present to work with C# -- and no book like this one to teach you everything you need to know. Special note to VB6 and Java programmers: if you've decided to transition to .NET, this book will take you there.

Author(s): Jesse Liberty; Donald Xie
Edition: 5
Publisher: O'Reilly Media
Year: 2007

Language: English
Pages: 608

Programming C# 3.0, Fifth Edition
Table of Contents
Preface
C# and .NET
About This Book
What You Need to Use This Book
How This Book Is Organized
Part I: The C# Language
Part II: C# and Data
Part III: Programming with C#
Part IV: The CLR and the .NET Framework
Who This Book Is For
Conventions Used in This Book
Support
We’d Like to Hear from You
Using Code Examples
Safari® Books Online
Acknowledgments
From Jesse Liberty
From Donald Xie
Dedications
From Jesse Liberty
From Donald Xie
Part I The C# Language
C# 3.0 and .NET 3.5
The Evolution of C#
The C# Language
A Tiny Bit of History
C# Features
The .NET Platform
Getting Started: “Hello World”
Classes, Objects, and Types
Methods
Comments
Console Applications
Namespaces
The Dot Operator (.)
The using Directive
Case Sensitivity
The static Keyword
Developing “Hello World”
Editing “Hello World”
Compiling and Running “Hello World”
Using the Visual Studio 2008 Debugger
C# Language Fundamentals
Types
The Built-In Types
Choosing a built-in type
Converting built-in types
Variables and Constants
Definite Assignment
Constants
Enumerations
Strings
Identifiers
Whitespace
Statements
Unconditional Branching Statements
Conditional Branching Statements
if...else statements
Nested if statements
switch statements: an alternative to nested ifs
Switch on string statements
Iteration Statements
The goto statement
The while loop
The do...while loop
The for loop
The foreach statement
The continue and break statements
Operators
The Assignment Operator (=)
Mathematical Operators
Simple arithmetical operators (+, -, *, /)
The modulus operator (%) to return remainders
Increment and Decrement Operators
Calculate and reassign operators
The prefix and postfix operators
Relational Operators
Use of Logical Operators with Conditionals
Operator Precedence
The Ternary Operator
Preprocessor Directives
Defining Identifiers
Undefining Identifiers
#if, #elif, #else, and #endif
Classes and Objects
Defining Classes
Access Modifiers
Method Arguments
Creating Objects
Constructors
Initializers
The ICloneable Interface
The this Keyword
Using Static Members
Invoking Static Methods
Using Static Constructors
Static Classes
Using Static Fields
Destroying Objects
The C# Destructor
Destructors Versus Dispose
Implementing the Close() Method
The using Statement
Passing Parameters
Passing by Reference
Overcoming Definite Assignment with out Parameters
Overloading Methods and Constructors
Encapsulating Data with Properties
The get Accessor
The set Accessor
Property Access Modifiers
readonly Fields
Inheritance and Polymorphism
Specialization and Generalization
Inheritance
Implementing Inheritance
Polymorphism
Creating Polymorphic Types
Creating Polymorphic Methods
Calling Base Class Constructors
Controlling Access
Versioning with the new and override Keywords
Abstract Classes
Limitations of Abstract
Sealed Class
The Root of All Types: Object
Nesting Classes
Operator Overloading
Using the operator Keyword
Supporting Other .NET Languages
Creating Useful Operators
Logical Pairs
The Equality Operator
Conversion Operators
Putting Operators to Work
Structs
Defining Structs
Creating Structs
Structs As Value Types
Interfaces
Defining and Implementing an Interface
Implementing More Than One Interface
Extending Interfaces
Combining Interfaces
Polymorphism with Interfaces
Interface Versus Abstract Class
Overriding Interface Implementations
Explicit Interface Implementation
Selectively Exposing Interface Methods
Member Hiding
Arrays, Indexers, and Collections
Arrays
Declaring Arrays
Understanding Default Values
Accessing Array Elements
The foreach Statement
Initializing Array Elements
The params Keyword
Multidimensional Arrays
Rectangular arrays
Jagged arrays
Array Bounds
Array Conversions
Sorting Arrays
Indexers
Indexers and Assignment
Indexing on Other Values
Collection Interfaces
The IEnumerable Interface
Constraints
List
Implementing IComparable
Implementing IComparer
Queues
Stacks
Dictionaries
IDictionary
Strings and Regular Expressions
Strings
Creating Strings
The ToString() Method
Manipulating Strings
Finding Substrings
Splitting Strings
Manipulating Dynamic Strings
Regular Expressions
Using Regular Expressions: Regex
Using Regex Match Collections
Using Regex Groups
Using CaptureCollection
Exceptions
Throwing and Catching Exceptions
The throw Statement
The catch Statement
Taking corrective action
Unwinding the call stack
Try/Catch Best Practices
The finally Statement
Exception Objects
Delegates and Events
Events
Events and Delegates
Indirect Invocation
Publish and Subscribe/Observer
The Publishing Class: Clock
Registering to Be Notified
Sequence of Events
The Danger with Delegates
The event Keyword
Anonymous Methods
Lambda Expressions
Callback Methods
Part II C# and Data
Introducing LINQ
Defining and Executing a Query
Creating the Query
The from clause
Filtering
Projection (or select)
Deferred Query Evaluation
LINQ and C#
Joining
Ordering and the var Keyword
Grouping and the group Keyword
Anonymous Types
Implicitly Typed Local Variables
Extension Methods
Defining and Using Extension Methods
Extension Method Restrictions
Lambda Expressions in LINQ
Working with XML
XML Basics (A Quick Review)
Elements
XHTML
X Stands for eXtensible
Creating XML Documents
XML Elements
XML Attributes
Searching in XML with XPath
Searching for a Single Node
Searching Using Axes
Predicates
XPath Functions
Searching Using XPathNavigator
Using XPathNodeIterator
Using XPathExpression
XML Serialization
Customizing XML Serialization Using Attributes
Runtime XML Serialization Customization
Putting LINQ to Work
Getting Set Up
LINQ to SQL Fundamentals
Using Visual Studio LINQ to SQL Designer
Retrieving Data
Creating Properties for Each Table
A LINQ Query
Updating Data Using LINQ to SQL
Adding a Customer Record
Modifying a Customer Record
Deleting Relational Data
LINQ to XML
ADO.NET and Relational Databases
Relational Databases and SQL
Tables, Records, and Columns
Normalization
Declarative Referential Integrity
SQL
The ADO.NET Object Model
DataTables and DataColumns
DataRelations
Rows
Data Adapter
DBCommand and DBConnection
DataReader
Getting Started with ADO.NET
Part III Programming with C#
Programming ASP.NET Applications
Web Forms Fundamentals
Web Forms Events
Postback versus nonpostback events
State
Web Forms Life Cycle
Creating a Web Form
Code-Behind Files
Adding Controls
Server Controls
Data Binding
Examining the Code
Adding Controls and Events
Programming WPF Applications
WPF in a Very Small Nutshell
Creating a WPF Example
The Example Program
Building the Application
Grids and Stack Panels
Sucking on a Fire Hose
Our goals
Adding Data
Instantiating objects declaratively
Using the Data in the XAML
Defining the Listbox
The Complete XAML File
Event Handling (Finally!)
What Have You Learned, Dorothy?
Programming Windows Forms Applications
Creating the Application
Creating Event Handlers
Populating the TreeView Controls
TreeNode objects
Recursing through the subdirectories
Getting the files in the directory
Handling TreeView Events
Clicking the source TreeView
Expanding a directory
Clicking the target TreeView
Handling the Clear button event
Implementing the Copy Button Event
Getting the selected files
Sorting the list of selected files
Handling the Delete Button Event
Part IV The CLR and the .NET Framework
Attributes and Reflection
Attributes
Types of Attributes
Attribute targets
Applying attributes
Custom Attributes
Declaring an attribute
Naming an attribute
Constructing an attribute
Using an attribute
Reflection
Viewing Metadata
Type Discovery
Reflecting on a Type
Finding all type members
Finding type methods
Finding particular type members
Late Binding
Threads and Synchronization
Threads
Starting Threads
Joining Threads
Blocking Threads with Sleep
Killing Threads
Synchronization
Using Interlocked
Using Locks
Using Monitors
Race Conditions and Deadlocks
Race Conditions
Deadlocks
Streams
Files and Directories
Working with Directories
Creating a DirectoryInfo Object
Working with Files
Modifying Files
Reading and Writing Data
Binary Files
Buffered Streams
Working with Text Files
Asynchronous I/O
Network I/O
Creating a Network Streaming Server
Creating a Streaming Network Client
Handling Multiple Connections
Asynchronous Network File Streaming
Web Streams
Serialization
Using a Formatter
Working with Serialization
Serializing the object
Deserializing the object
Handling Transient Data
Isolated Storage
Programming .NET and COM
Importing ActiveX Controls
Creating an ActiveX Control
Importing a Control in .NET
Importing a control
Manually importing the control
Adding the control to the form
P/Invoke
Pointers
C# Keywords
Index